What is the recommended way in Golang to download a submodule of a dependency? I think my question can be best described by examples.
Example #1:
I have a client and a server. My server is an API and has a bunch of other dependencies, such as databases, messages queues, consul, and etc. I would like my client to be a lightweight package where users download only few dependencies needed for the client.
You could say that the client and server can be on separate repositories. However, there may also be some common code amongst them, which if we follow this pattern, would again be another repository.
I'm thinking of some structure that looks like this:
service/
---> common/
------> redis.go
------> kafka.go
---> client/
------> client.go
---> server/
------> database/
------> swagger/
------> producer/
------> etc/
Example #2:
It's pretty common for projects to share models. If we have microservices that communicate through message brokers with a common model, we'd probably want some structure like this.
service/
---> model/
------> message.go
---> service1/
---> service2/
Comparison to other languages
I am from a Scala/Java background and have started to use Golang less than a month. Comparing with Scala, I could have handled this in two ways. Let's take Example #2
- Publish model as its own jar and import
model.jar
in each service - Use multi-project setup in sbt: https://www.scala-sbt.org/1.x/docs/Multi-Project.html.
Some Things I Explored in Go
- https://blog.gopheracademy.com/advent-2015/vendor-folder/
- https://github.com/golang/go/wiki/Modules#faqs--multi-module-repositories
But so far they don't seem to solve my question
Final Question
What is the recommended way in Golang to tackle the issues I stated in the examples?
Thank you for your help!