zoukankan      html  css  js  c++  java
  • 使用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 
    
    博客内容仅供参考,部分参考他人优秀博文,仅供学习使用
  • 相关阅读:
    PHP 构造方法 __construct()(转)
    PHP笔记
    php的print_r第二个参数是true有啥用啊
    如何给类或方法规范地注释
    详解spl_autoload_register()  函数(转)
    PHP中文网上的分页代码
    echo 0000
    [csu/coj 1619] 递归
    [csu/coj 1083]贪心
    [csu/coj 1078]多个序列的最长公共子序列
  • 原文地址:https://www.cnblogs.com/linagcheng/p/14667942.html
Copyright © 2011-2022 走看看