Makefile 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. SHELL=cmd
  2. .PHONY: all clean check lint cover build_api_win build_rpc_win help
  3. all:clean check cover
  4. modInit: go mod init userCenter
  5. modTidy: go mod tidy
  6. genRpc:
  7. cd rpc && goctl rpc protoc userCenter.proto --go_out=. --go-grpc_out=. --zrpc_out=.
  8. @echo "===========> genRpc finish"
  9. genApi:
  10. cd api/ && goctl api go -api userCenter.api -dir .
  11. @echo "===========> genApi finish"
  12. #格式化动作
  13. check:
  14. #格式化代码
  15. go fmt ./
  16. @echo "===========> fmt finish"
  17. #一般错误检查
  18. go vet ./
  19. @echo "===========> vet finish"
  20. #会把指定代码包的所有Go语言源码文件中的旧版本代码修正为新版本的代码。这里所说的版本即Go语言的版本
  21. go fix ./
  22. @echo "===========> fix finish"
  23. #跑静态分析
  24. lint:
  25. golangcli-lint run --enable-all
  26. #定义变量
  27. API_LINUX_FILE=./api/usercenter_linux
  28. API_WIN_FILE=./api/usercenter.exe
  29. RPC_LINUX_FILE=./rpc/usercenter_linux
  30. RPC_WIN_FILE=./rpc/usercenter.exe
  31. #编译api--linux
  32. build_api_linux:
  33. SET GOARCH=amd64
  34. SET GOOS=linux
  35. go build -ldflags="-s -w" -o ${API_LINUX_FILE} ./api/usercenter.go
  36. #编辑api--win
  37. build_api_win:
  38. @echo "===========> windows go build api "
  39. go build -ldflags="-s -w" -o ${API_WIN_FILE} ./api/usercenter.go
  40. #编译rpc--linux
  41. build_rpc_linux:
  42. SET GOOS=linux
  43. SET GOARCH=amd64
  44. go build -ldflags="-s -w" -o ${RPC_LINUX_FILE} ./rpc/usercenter.go
  45. #编辑rpc--win
  46. build_rpc_win:
  47. @echo "===========> windows go build rpc "
  48. go build -ldflags="-s -w" -o ${RPC_WIN_FILE} ./rpc/usercenter.go
  49. #单元测试覆盖率
  50. cover:
  51. @echo "===========> Run go test "
  52. cd service/ && go test -v -covermode=count -coverprofile=test_cover.out && go tool cover -html=test_cover.out -o coverage.html
  53. #清理
  54. clean:
  55. go clean
  56. cd rpc && del *.exe
  57. cd api && del *.exe
  58. cd service && del *.html
  59. cd service && del *.out
  60. #显示帮助
  61. help:
  62. @echo "make all 执行"
  63. @echo "make modInit 初始化go.mod文件"
  64. @echo "make modTidy 更新go.mod"
  65. @echo "make genRpc 初始rpc"
  66. @echo "make genApi 初始化api"
  67. @echo "make check fmt、vet、fix代码静态检查"
  68. @echo "make lint lint代码静态走查"
  69. @echo "make build_api_mac 编译api->Mac可执行文件"
  70. @echo "make build_api_linux 编译api->Linux可执行文件"
  71. @echo "make build_api_win 编译api->windows可执行文件"
  72. @echo "make build_rpc_mac 编译rpc->Mac可执行文件"
  73. @echo "make build_rpc_linux 编译rpc->Linux可执行文件"
  74. @echo "make build_rpc_win 编译rpc->windows可执行文件"
  75. @echo "make cover 单元测试用例覆盖率"
  76. @echo "make clean 清理"