简体   繁体   English

go 构建,找不到路径模块

[英]go build, cannot find module for path

I get a golang project form github, I have inited go mod and modified relative import.我得到了一个来自 github 的 golang 项目,我已经启动了 go mod 并修改了相对导入。 but when execute go build main.go , error as follow:但是当执行go build main.go时,错误如下:

build _/D_/myCode/jd_seckill-1/common: cannot find module for path _/D_/myCode/jd_seckill-1/common

This is go.mod that created after I executed go mod init jdSeckill这是在我执行go mod init jdSeckill

module jdSeckill

go 1.13

require (
    github.com/Albert-Zhan/httpc v0.0.0-20210208112951-8d16c3e27c04
    github.com/PuerkitoBio/goquery v1.6.1
    github.com/tidwall/gjson v1.6.8
    golang.org/x/text v0.3.5
)

This is main.go have be modified by me这是主要的。go 已被我修改

package main

import (
    "jdSeckill/common"    //   ../common   before modified
    "jdSeckill/conf"      //   ../conf     before modified
    "jdSeckill/jd_seckill"
    "errors"
    "fmt"
    "github.com/Albert-Zhan/httpc"
    "github.com/tidwall/gjson"
    "log"
    "net/http"
    "os"
    "runtime"
    "sync"
    "time"
)

The common code as follow picture:常用代码如下图:

enter image description here在此处输入图像描述

Go's module functionality was designed for the public external modules. Go 的模块功能是为公共外部模块设计的。 If you want to use local modules, you should use "replace" directive of go mod如果你想使用本地模块,你应该使用 go mod 的“replace”指令

See here - https://github.com/golang/go/wiki/Modules见这里 - https://github.com/golang/go/wiki/Modules

Here is the example of the go mod replace:这是 go mod 替换的示例:

module github.com/user/service

replace github.com/user/depservice => /Users/user/Projects/depservice

require (
    github.com/user/depservice v1.1.1
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM