配置代理
文档: https://studygolang.com/articles/24517?fr=sidebar
goLand 配置
配置全球代理
vim ~/.bash_profile
> 添加环境变量
    
# 启用 Go Modules 功能
export GO111MODULE=on
# 配置 GOPROXY 环境变量
export GOPROXY=https://goproxy.io
    
source ~/.bash_profile
> OK
    module 常用命令
- go help mod
- go mod init
导入本地包
如果项目有.git目录使用如下命令
go mod init 
否则
go mod init packgeName
创建一个本地包
例如: ch > format.go
package ch
import (
    "fmt"
    "reflect"
    "time"
)
func Format(time time.Time) string  {
    fmt.Println(reflect.TypeOf(time))
    t := time.Format("2006-01-02 15:04:05")
    return t
}
func ParseTimestamp(t int64) time.Time {
    nt := time.Unix(t, 0)
    return nt
}
使用
> main.go
package main
import (
    "fmt"
    "os"
    "time"
    "imp/ch"
)
func main()  {
    args := os.Args[1:]
    if len(args) == 0 {
        nowTime := time.Now()
        formatTime := ch.Format(nowTime)
        fmt.Println(formatTime)
        fmt.Println(nowTime)
        return
    }
    for _, arg := range args {
        fmt.Println(arg)
    }
}
> go.mod
> ----
module imp
go 1.13
replace imp/ch => ./ch
常用命令
- go mod init
- go help mod
- go mod tidy
			本文由 邓尘锋 创作,采用 知识共享署名4.0 国际许可协议进行许可
本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名
最后编辑时间为: Mar 22, 2021 at 04:58 pm		
