go run build install test

本文介绍了Go语言中的几个常用命令,包括runbuildinstall、goenv、gorun、gobuild等,并提供了详细的使用方法和注意事项。同时,文章还涵盖了如何进行测试、压力测试等内容。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用

0.run build install 可以看这篇,感觉写得特别好
https://studygolang.com/articles/10572

1.go env

2.go rungo build

只要设置好$GOPATH 就可以使用

go run main.go
go run src/main.go # 相对路径课也可以

src 内,go build 不用加文件名

  1. go build

只要设置好$GOPATH 就可以使用

go build # 在 src 内,go build不用加文件名
go build main.go
go build src/main.go # 相对路径课也可以

4.install
build,但是会吧生成的文件放入pkg或者bin文件夹中

5.test

go test -v packagename
go test -v filename1,filename2,filename3

-v 显示测试的详细信息

测试

压力测试参考:
https://blog.youkuaiyun.com/code_segment/article/details/77507491
闭包和flag.parse()
http://blog.studygolang.com/2017/10/how-to-test-with-go/

go build –ldflags

go build默认情况下是有 调试信息的,可以直接gdb调试
想要去掉调试信息,需要额外加参数,参考
https://studygolang.com/articles/7496

go build -ldflags "-w -s" ./hello.go

包名和目录名可以不一致

具体参考:
http://blog.studygolang.com/2012/12/go%E9%A1%B9%E7%9B%AE%E7%9A%84%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84/

在linux可以使用“make geth”,那在window下输入什么命令可以达到相应目的,以下是Makefile文件中的内容:“# This Makefile is meant to be used by people that do not usually work # with Go source code. If you know what GOPATH is then you probably # don't need to bother with make. .PHONY: geth all test lint fmt clean devtools help GOBIN = ./build/bin GO ?= latest GORUN = go run #? geth: Build geth. geth: $(GORUN) build/ci.go install ./cmd/geth @echo "Done building." @echo "Run \"$(GOBIN)/geth\" to launch geth." #? all: Build all packages and executables. all: $(GORUN) build/ci.go install #? test: Run the tests. test: all $(GORUN) build/ci.go test #? lint: Run certain pre-selected linters. lint: ## Run linters. $(GORUN) build/ci.go lint #? fmt: Ensure consistent code formatting. fmt: gofmt -s -w $(shell find . -name "*.go") #? clean: Clean go cache, built executables, and the auto generated folder. clean: go clean -cache rm -fr build/_workspace/pkg/ $(GOBIN)/* # The devtools target installs tools required for 'go generate'. # You need to put $GOBIN (or $GOPATH/bin) in your PATH to use 'go generate'. #? devtools: Install recommended developer tools. devtools: env GOBIN= go install golang.org/x/tools/cmd/stringer@latest env GOBIN= go install github.com/fjl/gencodec@latest env GOBIN= go install google.golang.org/protobuf/cmd/protoc-gen-go@latest env GOBIN= go install ./cmd/abigen @type "solc" 2> /dev/null || echo 'Please install solc' @type "protoc" 2> /dev/null || echo 'Please install protoc' #? help: Get more info on make commands. help: Makefile @echo '' @echo 'Usage:' @echo ' make [target]' @echo '' @echo 'Targets:' @sed -n 's/^#?//p' $< | column -t -s ':' | sort | sed -e 's/^/ /'”
03-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值