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/下。

  • 相关阅读:
    P1522 牛的旅行
    P1908 逆序对
    P1107 雷涛的小猫
    欧拉函数
    P2679 子串
    P1063 能量项链
    P1052 过河
    P1020 导弹拦截
    P1330 阳光封锁大学
    P1198 最大数
  • 原文地址:https://www.cnblogs.com/smartrui/p/9974202.html
Copyright © 2011-2022 走看看