README.md 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# GitLab Go

## 开发命令

### get

```shell
go get -u github.com/urfave/cli/v2
```

### mod

```shell
go mod tidy
```

徐晓伟's avatar
徐晓伟 已提交
17 18 19 20
```shell
go mod download
```

21 22 23 24 25 26 27 28
### run

```shell
go run main.go
```

### run help

徐晓伟's avatar
徐晓伟 已提交
29 30 31 32
```shell
go run main.go help
```

33 34 35 36 37 38 39 40
```shell
$ go run main.go help
NAME:
   boom - make an explosive entrance

USAGE:
   boom [global options] command [command options] [arguments...]

徐晓伟's avatar
徐晓伟 已提交
41 42 43
VERSION:
   v0.0.1-snapshot

44 45 46 47
COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
徐晓伟's avatar
徐晓伟 已提交
48 49
   --help, -h     show help
   --version, -v  print the version
50 51 52 53 54 55 56 57 58 59 60
```

### test

```shell
go test -v
```

### build

```shell
徐晓伟's avatar
徐晓伟 已提交
61 62 63 64 65
go build
# GOOS=:设置构建的目标操作系统(darwin | freebsd | linux | windows)
# GOARCH=:设置构建的目标操作系统(386 | amd64 | arm | arm64)
# -v:打印编译过程中的详细信息
# -ldflags:设置在编译时传递给链接器的参数
徐晓伟's avatar
徐晓伟 已提交
66 67 68 69
# -ldflags "-s -w -buildid="
#                           -s: 删除符号表信息,减小可执行文件的大小。
#                           -w: 删除调试信息,使可执行文件在运行时不会打印调试信息。
#                           -buildid=: 删除构建ID,使可执行文件在运行时不会打印构建ID。
徐晓伟's avatar
徐晓伟 已提交
70 71
# -trimpath:去掉所有包含 go path 的路径
# -o:指定构建后输出的文件名
72
```
徐晓伟's avatar
徐晓伟 已提交
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102

- Windows
    - amd64
        ```shell
        GOOS=windows GOARCH=amd64 go build -v -ldflags "-s -w -buildid=" -trimpath -o gitlab-go-windows-amd64.exe .
        ```
    - arm64
        ```shell
        GOOS=windows GOARCH=arm64 go build -v -ldflags "-s -w -buildid=" -trimpath -o gitlab-go-windows-arm64.exe .
        ```

- Linux
    - amd64
        ```shell
        GOOS=linux GOARCH=amd64 go build -v -ldflags "-s -w -buildid=" -trimpath -o gitlab-go-linux-amd64 .
        ```
    - arm64
        ```shell
        GOOS=linux GOARCH=arm64 go build -v -ldflags "-s -w -buildid=" -trimpath -o gitlab-go-linux-arm64 .
        ```

- Darwin
    - amd64
        ```shell
        GOOS=darwin GOARCH=amd64 go build -v -ldflags "-s -w -buildid=" -trimpath -o gitlab-go-darwin-amd64 .
        ```
    - arm64
        ```shell
        GOOS=darwin GOARCH=arm64 go build -v -ldflags "-s -w -buildid=" -trimpath -o gitlab-go-darwin-arm64 .
        ```