README.md 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
# GitLab Go

## 开发命令

### get

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

### mod

```shell
go mod tidy
```

### run

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

### run help

徐晓伟's avatar
徐晓伟 已提交
25 26 27 28
```shell
go run main.go help
```

29 30 31 32 33 34 35 36
```shell
$ go run main.go help
NAME:
   boom - make an explosive entrance

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

徐晓伟's avatar
徐晓伟 已提交
37 38 39
VERSION:
   v0.0.1-snapshot

40 41 42 43
COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
徐晓伟's avatar
徐晓伟 已提交
44 45
   --help, -h     show help
   --version, -v  print the version
46 47 48 49 50 51 52 53 54 55 56
```

### test

```shell
go test -v
```

### build

```shell
徐晓伟's avatar
徐晓伟 已提交
57 58 59 60 61
go build
# GOOS=:设置构建的目标操作系统(darwin | freebsd | linux | windows)
# GOARCH=:设置构建的目标操作系统(386 | amd64 | arm | arm64)
# -v:打印编译过程中的详细信息
# -ldflags:设置在编译时传递给链接器的参数
徐晓伟's avatar
徐晓伟 已提交
62 63 64 65
# -ldflags "-s -w -buildid="
#                           -s: 删除符号表信息,减小可执行文件的大小。
#                           -w: 删除调试信息,使可执行文件在运行时不会打印调试信息。
#                           -buildid=: 删除构建ID,使可执行文件在运行时不会打印构建ID。
徐晓伟's avatar
徐晓伟 已提交
66 67
# -trimpath:去掉所有包含 go path 的路径
# -o:指定构建后输出的文件名
68
```
徐晓伟's avatar
徐晓伟 已提交
69 70 71 72 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

- 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 .
        ```