关于go:go如何通过module新建公共包并导入使用

11次阅读

共计 410 个字符,预计需要花费 2 分钟才能阅读完成。

一、创立一个 Go Modules 我的项目

1、创立文件夹

mkdir tool && cd tool

2、初始化包 go mod init github.com/hisheng/tool

➜  go mod init github.com/hisheng/tool
go: creating new go.mod: module github.com/hisheng/tool

阐明:咱们把代码包发到 github 上。

3、增加业务代码

新建 tool.go 文件

➜ touch tool.go    

写入代码

package tool

func Hello() string {return "hello from tool project"}

二、公布到 github 近程代码仓库

git init
git add .
git commit -m "init"
git remote add origin https://github.com/hisheng/tool.git
git push -u origin master

三、如何拉取导入公共包

正文完
 0