欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

go常用命令

程序员文章站 2022-05-02 10:38:30
...

 

PROJECT_NAME := "test-go"

 

PKG := "github.com/test-go"

 

PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)

 

GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go)

 

 

 

.DEFAULT_GOAL := default

 

.PHONY: all dep build clean test lint fmt

 

 

 

all: build

 

 

 

fmt: ## Format the files

 

@gofmt -l -w $(GO_FILES)

 

 

 

fmtcheck: ## Check and format the files

 

@gofmt -l -s $(GO_FILES) | read; if [ $$? == 0 ]; then echo "gofmt check failed for:"; gofmt -l -s $(GO_FILES); fi

 

 

 

lint: ## Lint the files

 

@golint -set_exit_status ${PKG_LIST}

 

 

 

test: ## Run unittests

 

@go test -short ${PKG_LIST}

 

 

 

race: dep ## Run data race detector

 

@go test -race -short ${PKG_LIST}

 

 

 

msan: dep ## Run memory sanitizer

 

@go test -msan -short ${PKG_LIST}

 

 

 

dep: ## Get the dependencies

 

@go get -v -d ./...

 

 

 

build: dep ## Build the binary file

 

@go build -i -v $(PKG)

 

 

 

clean: ## Remove previous build

 

@go mod tidy

 

@rm -f $(PROJECT_NAME)

 

 

 

version: ## Print git revision info

 

@echo $(expr substr $(git -rev-parse HEAD) 1 8)

 

 

 

run: ## Build and run the application, eg: make run local => go run main.go --config=config/config-local.toml

 

@MODE=customer

 

@ARGs=$(filter-out $@,$(MAKECMDGOALS))

 

@echo use config/config-"$$MODE".toml

 

@if [ "$(ARGs)" != "" ]; then  \

 

go run main.go --config=config/config-"$$ARGs".local.toml; \

 

fi

 

 

 

help: ## Display this help screen

 

@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

 

 

 

default:

 

@echo default target