go get获取的依赖库和dep获取的vendor目录下的依赖库不一致的问题------玩下Gopkg.toml

版权声明:本文为博主原创文章,转载时请务必注明本文地址, 禁止用于任何商业用途, 否则会用法律维权。 https://blog.csdn.net/stpeace/article/details/84238982

        代码:

package main

import (
	"fmt"
	"github.com/satori/go.uuid"
)

func main() {
	u1 := uuid.Must(uuid.NewV4())
	fmt.Printf("UUIDv4: %s\n", u1)

	u2, err := uuid.NewV4()
	if err != nil {
		fmt.Printf("error: %s", err)
		return
	}
	fmt.Printf("UUIDv4: %s\n", u2)
}

       用go get -u github.com/satori/go.uuid, 上述程序运行OK,  但是如果用dep init获取,就出现如下错误:

# command-line-arguments
./a.go:9:17: not enough arguments in call to uuid.Must
        have (uuid.UUID)
        want (uuid.UUID, error)
./a.go:12:10: assignment mismatch: 2 variables but 1 values

       原因是:go get -u github.com/satori/go.uuid获取的包和dep init获取的包(vendor目录下)不一致

       

      解决方法1: 不用vendor

      解决方法2: 删除dep init生成的Gopkg.lock和vendor,  修改 Gopkg.toml中的内容, 然后dep ensure去获取对应分支的依赖库。 修改的内容如下:

[[constraint]]
  name = "github.com/satori/go.uuid"
  #version = "1.2.0"
  branch = "master" 

       好好理解下, 不多说。

猜你喜欢

转载自blog.csdn.net/stpeace/article/details/84238982