• 使用go mod管理依赖时,build出现问题


    Golang build失败

    使用go mod管理依赖时,build出现问题

    复现

    $ go build test.go
    

    出现以下错误:

    test.go:9:8: no required module provides package github.com/Unknwon/goconfig: working directory is not part of a module
    test.go:10:8: no required module provides package gopkg.in/confluentinc/confluent-kafka-go.v1/kafka: working directory is not part of a module
    

    原因

    未初始化模块

    解决方案

    go mod init
    go mod init example.com/m
    go get github.com/Unknwon/goconfig
    go build test.go 
    
    up@up123:~/scripts$ go mod init
    go: cannot determine module path for source directory /home/up/scripts (outside GOPATH, module path must be specified)
    
    Example usage:
            'go mod init example.com/m' to initialize a v0 or v1 module
            'go mod init example.com/m/v2' to initialize a v2 module
    
    Run 'go help mod init' for more information.
    
    
    
    up@up123:~/scripts$ go mod init example.com/m
    go: creating new go.mod: module example.com/m
    go: to add module requirements and sums:
            go mod tidy
    
    
    up@up123:~/scripts$ go build test.go 
    asset_traffic_producer.go:9:8: no required module provides package github.com/Unknwon/goconfig; to add it:
            go get github.com/Unknwon/goconfig
    asset_traffic_producer.go:10:8: no required module provides package gopkg.in/confluentinc/confluent-kafka-go.v1/kafka; to add it:
            go get gopkg.in/confluentinc/confluent-kafka-go.v1/kafka
    
    
    up@up123:~/scripts$ go get github.com/Unknwon/goconfig
    go get: added github.com/Unknwon/goconfig v0.0.0-20200908083735-df7de6a44db8
    
    up@up123:~/scripts$ go get gopkg.in/confluentinc/confluent-kafka-go.v1/kafka
    go get: added github.com/confluentinc/confluent-kafka-go v1.6.1
    go get: added gopkg.in/confluentinc/confluent-kafka-go.v1 v1.6.1
    
    
    up@up123:~/scripts$ go build test.go 
    
    博客内容仅供参考,部分参考他人优秀博文,仅供学习使用
  • 相关阅读:
    Windows phone 应用开发[9]单元测试
    Git Tool Part 2
    Windows phone 应用开发[6]Managed Extensibility Framework应用程序扩展
    也谈存储过程分页
    上传图像到sqlserver
    这两段代码是不同的
    TextBox中的TextChanged和KeyDown事件的小区别
    发现发现返回一条记录的datareader的新用法
    最近好多疑问啊!高手给点意见吧!
    csdn论坛去不了,只有在这里问了
  • 原文地址:https://www.cnblogs.com/linagcheng/p/14667942.html
Copyright © 2020-2023  润新知