Publishing a module
步骤
-
gitee 创建一个 repo git@gitee.com:xxxx/publish-module-demo.git(xxxx 一般为 gitee 用户名)
-
创建一个项目
go mod init gitee.com/xxxx/publish-module-demo
go.mod 的 module 必须为 gitee.com/xxxx/publish-module-demo
-
编写代码
gitee.com/xxxx/publish-module-demo/helloworld.go
package helloworld func SayHello() { println("hello world.") }
gitee.com/xxxx/publish-module-demo/helloworld_test.go
package helloworld import "testing" func TestSayHello(t *testing.T) { SayHello() }
-
执行 go mod tidy
go mod tidy
-
执行测试
$ go test ./... ok gitee.com/xxxx/publish-module-demo 0.015s
-
commit and tag
git init git add . git commit -m "publish-module-demo: changes for v0.1.0" git tag v0.1.0
-
push
git remote add origin git@gitee.com:xxxx/publish-module-demo.git git push origin master git push origin v0.1.0
-
在其他项目导入
go get gitee.com/xxxx/publish-module-demo/helloworld