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

  • 相关阅读:
    Flash、Ajax各自的优缺点,在使用中如何取舍?
    纯CSS气泡框实现方法探究
    CSS里padding和margin的区别是什么?
    img图片标签alt和title属性的区别
    JS中都有哪些数据类型呢?
    剑指offer---按只字形顺序打印二叉树
    剑指offer---序列化二叉树
    剑指offer---二叉树的下一个结点
    剑指offer---二叉树的深度
    剑指offer---平衡二叉树
  • 原文地址:https://www.cnblogs.com/gao88/p/11061914.html
Copyright © 2011-2022 走看看