官方教程地址:https://golang.google.cn/doc/tutorial/call-module-code

1.编写含有导入包的代码

package main

import "fmt"

import "rsc.io/quote" // 编辑器可能会提示找不到,不要着急 这个执行run的时候会自动下载

func main() {
    fmt.Println(quote.Go())
}

2.生成go.mod记录导入包的版本等信息

// hello 可以换成其他的字符
go mod init hello

3.执行run命令自动导入引入的外部包

go run hello.go

4.国内会出现导入外部包超时问题,在命令行输入以下内容解决

// 引用自 https://blog.csdn.net/qingshuiwater/article/details/109225888
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.io,direct

 

相关文章:

  • 2022-12-23
  • 2021-12-31
  • 2021-07-16
  • 2021-05-07
  • 2021-05-31
  • 2021-12-15
猜你喜欢
  • 2022-12-23
  • 2021-05-22
  • 2021-04-28
  • 2021-11-02
  • 2022-02-17
  • 2021-11-30
相关资源
相似解决方案