简体   繁体   中英

How to import gitsubmodule containing golang code with go.mod and go.sum file

I am facing issue in importing a gitsubmodule containing golang package with go.mod and go.sum file inside the package inside main project directory. But facing issue in importing the package.

go.mod inside gitsubmodule package

module abc

go 1.18

go.mod inside main project directory

module def

go 1.18

files inside the gitsubmodule go package has imports

package abc

import "abc/sample"

file for main project package

package main

import "def/abc/sample"


the structure of my project code is like this:-

|── go.sum
|── go.mod
|── main.go import "def/abc"
abc
    ├── constant
    |    ├── constant.go
    ├── abc.go  ----> import "abc/constant"
    |── go.mod
    |── go.sum

and but import "abc/constant" giving problem for gitsubmodule saying import error when I try to run main.go file

the solution to this problem is inside the main go.mod file add the following line

replace abc => ./abc

and do go mod tidy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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