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

  • 相关阅读:
    Map
    Set
    集合&List
    wepy的创建与运行
    vue post请求设置为FormData传参
    数据缓存sessionStorage、localStorage、cookie、session间的区别与联系
    vue中后退不刷新页面(使用keepAlive方法)
    vue点击按钮会刷新页面
    el-date-picker日期选择器 ——[Vue warn]: Error in render: "TypeError: date.getFullYear is not a function" found in
    element-ui 中表格嵌套表单(一) 如何给table表头添加必填*星号
  • 原文地址:https://www.cnblogs.com/gao88/p/11061914.html
Copyright © 2011-2022 走看看