Home > Blockchain >  Import go module in project to another module in the same project
Import go module in project to another module in the same project

Time:06-26

I have the following project structure:

.
├── daos
│   ├── daos.go
│   ├── daos.iml
│   ├── go.mod
│   └── go.sum
├── entities
│   ├── entities
│   │   └── pets.go
│   ├── entities.iml
│   └── go.mod
└── pkg.iml

I want to import module entities to daos, but get the following error:

go: finding module for package github.com/goncharovmvdev/pets/entities/pets
github.com/goncharovmvdev/pets/daos imports
    github.com/goncharovmvdev/pets/entities/pets: module github.com/goncharovmvdev/pets@latest found (v0.0.0-20220625073141-e49db91a04de), but does not contain package github.com/goncharovmvdev/pets/entities/pets

CodePudding user response:

If you want to import the entities to daos, there are 2 ways:

  1. Push the entities' source code to your Github.
  2. You can use the replace directive like this (https://go.dev/doc/tutorial/call-module-code)
  • Related