golang 1.4 mod 使用经验

perryn · · 1058 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

1.go mod 替代原来gopath的功能(可能理解有误)

2.go mod init 一个golang 项目

  • go mod 的命令使用
$ go help mod
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


  • glusterfs-benchmark项目信息

···
//进入glusterfs-benchmark目录
cd glusterfs-benchmark
go mod init glusterfs-benchmark
//会在 lusterfs-benchmark目录中 生成go.mod的文件
···

  • 项目目录架构
[perrynzhou@Debian ~/Source/perryn/glusterfs-benchmark]$ tree ../glusterfs-benchmark/
../glusterfs-benchmark/
├── api
│   ├── fuse_fetch.go
│   └── glfs_fetch.go
├── conf
│   └── conf.go
├── go.mod
├── metric
│   └── metric.go
├── pkg
│   └── mod
│       └── cache
│           └── lock
└── utils
    └── utils.go

14 directories, 114 files

  • 引入glusterfs-benchmark/api/fuse_fetch.go中引入utils库本地库
// fuse_fetch.go的包信息
package api

import (
    "bufio"
    "fmt"
    utils "github.com/perryn/glusterfs-benchmark/utils"
    "os"
    "path/filepath"
    "sync"
)
//修改go.mod文件
module glusterfs-benchmark

go 1.14

//新增这个命令
replace github.com/perryn/glusterfs-benchmark => ../glusterfs-benchmark

require github.com/perryn/glusterfs-benchmark v0.0.0-00010101000000-000000000000

//goland中去go get这个包后go.mod内容会自动添加如下信息
require github.com/perryn/glusterfs-benchmark v0.0.0-00010101000000-000000000000

有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:perryn

查看原文:golang 1.4 mod 使用经验

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1058 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传