zoukankan      html  css  js  c++  java
  • 在Go1.11.1中使用go module管理依赖

    今天试验了一下go的版本管理Go moule,只是安装了下,由于目前还没有进行大的项目开发,暂时没有碰到坑。
    使用了模块后,可以不用在GOPATH中再建立src目录了,直接在GOPATH中就行
    另外,大部分的GO子命令都知道如何处理一个模块,如 run,get, build, install, list等,就是说如果存在go.mod文件。
    你执行go run,go get ,go build....等会先去下载依赖的

    模块初始化

    go mod init gitlab.bytestar.io/grpc/grpc
    以上命令在当前目录生成go.mod文件 ,只有一行 module gitlab.bytestar.io/grpc/grpcapi
    这个文件不用手动维护,通过安装和删除依赖,会同步更新,维护好这个文件就行了
    这个文件有一个替换功能,就是如果有被墙的包,可以用替换的方式。不像在GOPATH时候,自已需要手动去替换。

    module gitlab.bytestar.io/grpc/grpcapi
    replace (
        golang.org/x/text => github.com/golang/text v0.3.0
    )
    

    其它可参考帮助

    go mod help
    

    Usage:

        go mod <command> [arguments]
    

    The commands are:

        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 tidy
    这条命令会自动更新依赖关系,并且将包下载放入cache。在GOPATH/pkg/mod/下。

  • 相关阅读:
    文件操作_1-24 选择题
    文件操作_1-22 选择题
    文件操作_1-21 选择题
    druid与知乎平台
    b树和b+树
    mybatis generator的generatorConfig.xml配置详解
    logback日志配置文件
    单链表每k个节点为一组进行反转(最后不满k个时不反转)
    单链表每k个节点一组进行反转(最后不足k个也反转)
    shell 结合expect实现ssh登录并执行命令
  • 原文地址:https://www.cnblogs.com/smartrui/p/9974202.html
Copyright © 2011-2022 走看看