zoukankan      html  css  js  c++  java
  • go mod

    golang 终于出官方版本管理机制,名为 go modules

    初体验

    使用前:

    # 先升级 golang 到 1.11 版本,然后
    export GO111MODULE=on

    在项目github.com/humboldt-xie/test-mod下,通过go mod init

    go mod init

    然后会在当前项目目录下出现 go.mod 文件,内容为:

    module github.com/humboldt-xie/test-mod

    编辑代码 main.go

    package main
    
    import (
    	"fmt"
    	"github.com/humboldt-xie/hlib/vmap"
    )
    
    func main() {
    	vmap := vmap.NewVMap()
    	fmt.Println("vim-go", vmap)
    }

    引用一个包

    然后,直接运行go build ./

    ➜  go build ./
    go: finding github.com/humboldt-xie/hlib/vmap latest
    go: finding github.com/humboldt-xie/hlib latest

    这时,会自动加载依赖包,并编译通过

    这时,多了一个文件go.sum,并且go.mod 也被修改了

    go.mod 则是描述直接依赖包(相当于glide.yaml)

    go.sum 则是描述依赖树锁定(相当于glide.lock)

    查看go.mod 文件内容,这时变为了

    module github.com/humboldt-xie/test-mod
    
    require github.com/humboldt-xie/hlib v0.0.0-20180903073735-6738efa10c3a

    go.sum 内容为

    github.com/humboldt-xie/hlib v0.0.0-20180903073735-6738efa10c3a h1:GgiozN6lA73wd7mQbJUdiEzW9CoBJM1Ey8A3G8RbsCo=
    github.com/humboldt-xie/hlib v0.0.0-20180903073735-6738efa10c3a/go.mod h1:Zdztzq6jaF9E1ZbVz6g5Kf/Thx4/guqFB3gxAkcNkGs=
    github.com/timtadh/data-structures v0.5.2 h1:yGrL+5Tf5mwRDPGnKwLeLOvfmoDsuKiMRmpETgGq+4w=
    github.com/timtadh/data-structures v0.5.2/go.mod h1:9R4XODhJ8JdWFEI8P/HJKqxuJctfBQw6fDibMQny2oU=

    go mod 还支持的命令:

    	download    download modules to local cache
    	edit        edit go.mod from tools or scripts
    	graph       print module requirement graph
    	init        initialize new module in current directory
    	tidy        add missing and remove unused modules
    	vendor      make vendored copy of dependencies
    	verify      verify dependencies have expected content
    	why         explain why packages or modules are needed

    存储

    go mod 下载的库,都存储在

    $GOPATH/pkg/mod/cache 下

    总结

    使用go mod 总共分为两步:

    go mod init
    
    go build ./

    十分简单

    来源:https://www.wafunny.com/blog/go/mod.html

  • 相关阅读:
    netcore 发布到IIS上常见错误
    mysql解压文件安装
    VS2017 怎么启用nuget程序包还原?
    vue-qr生成下载二维码
    控制器,action, 过滤器, 权限
    WebSocket浅析(一):实现群聊功能
    BOM元素之window对象
    arguments及arguments.callee
    Spring入门6事务管理2 基于Annotation方式的声明式事务管理机制
    Spring入门5.事务管理机制
  • 原文地址:https://www.cnblogs.com/gao88/p/11061914.html
Copyright © 2011-2022 走看看