Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Keep packages backwards compatible

Keep packages backwards compatible

FOSDEM 2017 talk on keeping Go packages backwards compatible

Ernesto Jiménez

February 05, 2017
Tweet

More Decks by Ernesto Jiménez

Other Decks in Programming

Transcript

  1. package example type Service struct { // ... } func

    New() *Service { return &Service{} }
  2. package example func Process(in input) error { // ... }

    // ⚠ type input interface { // ... }
  3. // Input exported for documentation type Input interface { //

    ... } func Process(in Input) error { // ... }
  4. package testing type TB interface { Error(args ...interface{}) Fail() //

    ... // contains filtered or unexported methods }
  5. package testing type TB interface { Error(args ...interface{}) Fail() //

    ... // A private method to prevent users implementing // interface and so future additions to it will // violate Go 1 compatibility. private() }
  6. // WithMaxDepth sets the max depth of the crawl func

    WithMaxDepth(depth int) Option { return func(opts *options) error { if depth < 0 { return fmt.Errorf("invalid depth: %d", depth) } opts.maxDepth = depth return nil } }