-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
52 lines (43 loc) · 1.13 KB
/
build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash
set -e
function cross_go_build(){
# CGO_ENABLED=0 GOOS=windows GOARCH=amd64
# CGO_ENABLED=0 GOOS=darwin GOARCH=amd64
# CGO_ENABLED=0 GOOS=darwin GOARCH=arm
# CGO_ENABLED=0 GOOS=linux GOARCH=amd64
binary="$3"
if [ "$1" == "windows" ]; then
binary="$3.exe"
fi
GO111MODULE=on CGO_ENABLED=1 GOOS=$1 GOARCH=$2 go build -v -ldflags "-s -w" -o "bin/$1_$2/$binary" "cli/$3/main.go"
}
function go_build(){
binary="$1"
GO111MODULE=on CGO_ENABLED=1 go build -v -ldflags "-s -w" -o "bin/$binary" "cli/$1/main.go"
}
function go_install(){
binary="$1"
GO111MODULE=on CGO_ENABLED=1 go build -v -ldflags "-s -w" -o "$(go env GOPATH)/bin/$binary" "cli/$1/main.go"
}
function format_golang_file () {
project_dir=$(realpath "$1")
# shellcheck disable=SC2044
for elem in $(find "${project_dir}" -name '*.go' | grep -v 'example/'); do
# echo "format ${elem}"
gofmt -w "${elem}" 2>&1;
goimports -w -srcdir "${project_dir}" -local "$2" "${elem}" 2>&1;
done
}
case $1 in
build)
go_build $2
;;
install)
go_install $2
;;
format)
format_golang_file . "github.com/anthony-dong/golang"
;;
*)
;;
esac