-2

I have this repo in github that have library for cpp and go in same repo. Now how can I create go.mod in the go to import it ?

I searched google about that but all are have Separate repo. How can i do it ?

Thanks.

kozmo
  • 4,024
  • 3
  • 30
  • 48
srilakshmikanthanp
  • 2,231
  • 1
  • 8
  • 25

1 Answers1

1

1️⃣. init module in sub dir:

cd /art/art-go

go mod init github.com/srilakshmikanthanp/art/art-go

2️⃣. add missing and remove unused modules for go.mod file

cd /art/art-go

go mod tidy

3️⃣.❗️ Because you have multimodule project, you have to add version tag with submodule declaration (<submodul_dir_name>/<version>) to submodule witch fit to Semantic Version specification

git commit -a - m "art/art-go - some changes"
git tag art-go/v1.0.0
git push
git push --tags 

4️⃣. ☝ thus, you can import it in other projects

module go mod init github.com/srilakshmikanthanp/otherproject

require github.com/srilakshmikanthanp/art/art-go v1.0.0

go 1.15

4️⃣. ✌ or get it

go get github.com/srilakshmikanthanp/art/art-go@v1.0.0

Output

go: finding github.com/srilakshmikanthanp/art/art-go v1.0.0
kozmo
  • 4,024
  • 3
  • 30
  • 48
  • Thanks for your answer, As you said i changed the folder structure but when i import throws error like `but does not contain package github.com/srilakshmikanthanp/art/art-go/anixt` in [go plagground](https://play.golang.org/p/IM4PRsKR2fv) – srilakshmikanthanp Sep 14 '20 at 05:57
  • Did you add version tag `art-go/v1.0.0`? – kozmo Sep 14 '20 at 06:00
  • `go get github.com/srilakshmikanthanp/art/art-go@v0.1.0` works fine `go: downloading github.com/srilakshmikanthanp/art/art-go v0.1.0` – kozmo Sep 14 '20 at 06:07