Giter Site home page Giter Site logo

gomodlib's Introduction

This is a test project to show how to use Go modules when building projects and libraries with many subpackages, where you want to be able to use different versions of those subpackages.

For example, let's say you have one team who owns a pg package and another team that owns a kafka package. You want to have the pg team be able to make changes to their package without unintentionally affecting the kafka package or users of the kafka package.

The key thing is to add a go.mod for each sub package, instead of having one top-level go.mod for the whole repo. Giving each sub package their own go.mod gives them their own identity from a go module perspective, as described in the go mod wiki. This allows you to control the sub package versions you depend on.

Here's an example of how you'd setup the go.mod of the project that's using the libraries:

module github.com/travisjeffery/gomodservice

require (
	github.com/travisjeffery/gomodlib v0.0.0-20190208085931-4eb83f17895c
	github.com/travisjeffery/gomodlib/subpkga v0.0.0-20190208085931-4eb83f17895c // indirect
	github.com/travisjeffery/gomodlib/subpkgb v0.0.0-20190208085931-4eb83f17895c // indirect
)

replace github.com/travisjeffery/gomodlib/subpkga => github.com/travisjeffery/gomodlib/subpkga v0.0.0-20190208090204-d8f7841ac5e3

The replace directive allows to control which version of the sub package you're using. In this case you're saying you want to use d8f7841ac5e3, so you can use the field added in that commit. If your project was updated to use different versions of the gomodlib or subpkgb packages, your project would continue to use subpkga@d8f7841ac5e3.

If you don't care about using specific sub package versions you don't need to work about any of this, just go get the root package and you're done.

gomodservice is an example of a project depending on your packages, the go.mod file in that project is how you'd set yours up as well.

gomodlib's People

Contributors

travisjeffery avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.