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

Finding Dependable Go Packages

B9c37c30e9e196fa2f2d52ce7b724677?s=47 Julie Qiu
May 31, 2019
1.2k

Finding Dependable Go Packages

At some point, we all find ourselves wanting to use a third-party Go package in our Go code. This talk discusses strategies for discovering, evaluating and maintaining Go packages and modules. It also shares new tools that the Go team is building to make this process better.

B9c37c30e9e196fa2f2d52ce7b724677?s=128

Julie Qiu

May 31, 2019
Tweet

Transcript

  1. Finding Dependable Go Packages Julie Qiu Google @jqiu25

  2. Julie Qiu Software Engineer Go Team Google @jqiu25

  3. How do I decide which package to use?

  4. @jqiu25

  5. @jqiu25

  6. None
  7. None
  8. None
  9. @jqiu25

  10. DESSERTS DINNER APPETIZERS BREAKFAST SNACKS HOME ! Avocado Green Goddess

    Dip " Cornbread Sausage Stuffing # Lemon Chicken Dill $ Tomato Soup with Grilled Cheese Croutons Julie’s Recipe Book
  11. @jqiu25 # Salmon with brown sugar and mustard Time: 20

    minutes ## Ingredients - Salmon - 1 tablespoon Dijon mustard - 2 tablespoons brown sugar ## Instructions 1. Heat oven to 400 degrees. 2. Mix Dijon mustard and brown sugar. 3. Salt and pepper the salmon. 4. Place salmon on a baking sheet. Slather on mustard and brown sugar mix. 5. Bake for 15 minutes. Salmon with Brown Sugar and Mustard Time: 20 minutes Ingredients • Salmon • Dijon mustard, 1 tablespoon • Brown sugar, 2 tablespoons Instructions 1. Heat oven to 400 degrees. 2. Mix Dijon mustard and brown sugar. 3. Salt and pepper the salmon. 4. Place salmon on a baking sheet. Slather on mustard and brown sugar mix. 5. Bake for 15 minutes.
  12. Image Storage Salmon with Brown Sugar and Mustard Time: 20

    minutes Ingredients • Salmon • Dijon mustard, 1 tablespoon • Brown sugar, 2 tablespoons
  13. @jqiu25 • Markdown parser • API to interact with image

    store • Image resizer • Search engine • … and more! Packages I need
  14. None
  15. Dependency Lifecycle Discovery Evaluation Maintenance

  16. Discovery

  17. @jqiu25 # Salmon with brown sugar and mustard Time: 20

    minutes ## Ingredients - Salmon - 1 tablespoon Dijon mustard - 2 tablespoons brown sugar ## Instructions 1. Heat oven to 400 degrees. 2. Mix Dijon mustard and brown sugar. 3. Salt and pepper the salmon. 4. Place salmon on a baking sheet. Slather on mustard and brown sugar mix. 5. Bake for 15 minutes. Salmon with Brown Sugar and Mustard Time: 20 minutes Ingredients • Salmon • Dijon mustard, 1 tablespoon • Brown sugar, 2 tablespoons Instructions 1. Heat oven to 400 degrees. 2. Mix Dijon mustard and brown sugar. 3. Salt and pepper the salmon. 4. Place salmon on a baking sheet. Slather on mustard and brown sugar mix. 5. Bake for 15 minutes.
  18. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 @jqiu25

  19. None
  20. @jqiu25

  21. Evaluation

  22. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 1. License @jqiu25

  23. DESSERTS DINNER APPETIZERS BREAKFAST SNACKS HOME ! Avocado Green Goddess

    Dip " Cornbread Sausage Stuffing # Lemon Chicken Dill $ Tomato Soup with Grilled Cheese Croutons Julie’s Recipe Book
  24. DESSERTS DINNER APPETIZERS BREAKFAST SNACKS HOME BIGGEST SALE EVER CLICK

    HERE EMAIL SUBSCRIBE Get a FREE blender! Julie’s Recipe Book ! Avocado Green Goddess Dip " Cornbread Sausage Stuffing # Lemon Chicken Dill $ Tomato Soup with Grilled Cheese Croutons
  25. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 2. Popularity @jqiu25

  26. { @jqiu25 Popularity Downloads Stars Forks Watchers Contributors Dependents

  27. { @jqiu25 Downloads Stars Forks Watchers Contributors Dependents Popularity

  28. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 3. Code Quality @jqiu25

  29. Image Storage Salmon with Brown Sugar and Mustard Time: 20

    minutes Ingredients • Salmon • Dijon mustard, 1 tablespoon • Brown sugar, 2 tablespoons
  30. { @jqiu25 @jqiu25 Code Quality Documentation

  31. @jqiu25 package blob import “thirdparty.com/blob” Package blob provides an API

    for interacting with Google Cloud Storage. It supports operations like reading, writing, and listing blobs in a bucket. // Open the bucket using default credentials. b, err := blob.OpenBucket("gs://recipe—pictures") defer b.Close() buf, err := bucket.ReadAll(ctx, "salmon.jpg") Example
  32. type Bucket Package blob provides an API for interacting with

    Google Cloud Storage. It supports operations like reading, writing, deleting and listing blobs in a bucket. Bucket is used to interact with blobs within a “bucket”, including read, write, and list operations. func OpenBucket OpenBucket opens the bucket identified by the URL given. @jqiu25 type Bucket struct { // contains unexported fields } func OpenBucket(urlstr string) (*Bucket, error) Example
  33. { @jqiu25 @jqiu25 Code Quality Documentation Tests

  34. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 @jqiu25

  35. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 @jqiu25

  36. { @jqiu25 @jqiu25 Code Quality Documentation Tests Idiomatic

  37. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 func OpenBucket(bucketName string) (*blob.Bucket,

    error) { drv, err := openBucket(bucketName) if err != nil { return nil, err } return blob.NewBucket(drv), nil } func OpenBucket(bucket_name string) (*blob.Bucket, error) { drv, err := openBucket(bucketName) if err != nil { return nil, err } return blob.NewBucket(drv), nil } Is the code gofmt’ed?
  38. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 func OpenBucket(bucketName string) (*blob.Bucket,

    error) { drv, err := openBucket(bucketName) if err != nil { log.Fatalf(“yolo: %v”, err) } return blob.NewBucket(drv), nil } func OpenBucket(bucketName string) (*blob.Bucket, error) { drv, err := openBucket(bucketName) if err != nil { return fmt.Errorf(“openBucket(%q): %v”, bucketName, err) } return blob.NewBucket(drv), nil } How are errors being handled?
  39. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 type Bucket interface {

    } func NewBucket(name string, age int) Bucket { } Are there unnecessary abstractions? type Bucket struct { } func NewBucket(name string, age int) *Bucket { }
  40. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 4. Upkeep @jqiu25

  41. { @jqiu25 Maintainer Activity Upkeep

  42. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 Upkeep: Maintainers

  43. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 @jqiu25 Upkeep: Commit History

  44. @jqiu25 Upkeep: Issue Tracker

  45. julieqiu commented 126 days ago This PR updates .travis.yml to

    test the most recent Go version.
  46. julieqiu commented 126 days ago @maintainer friendly ping julieqiu commented

    45 days ago This PR updates .travis.yml to test the most recent Go version.
  47. julieqiu commented 126 days ago @maintainer friendly ping julieqiu commented

    45 days ago @maintainer any updates? julieqiu commented 2 days ago This PR updates .travis.yml to test the most recent Go version.
  48. None
  49. { @jqiu25 Maintainer Activity API Stability Upkeep

  50. None
  51. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 What is a Module?

    ── go.mod ── go.sum ── … a bunch of packages
  52. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 What is a Module?

    ── go.mod ── go.sum ── blob ── gcsblob ── s3blob ── azureblob ── … more blobs
  53. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 1. Import compatibility rule

    @jqiu25 Modules & API Stability
  54. IMPORT COMPATIBILITY RULE If an old package and a new

    package have the same import path… 54
  55. IMPORT COMPATIBILITY RULE If an old package and a new

    package have the same import path… …the new package must be backwards compatible with the old package. 55
  56. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 1. Import compatibility rule

    2. Semantic versioning @jqiu25 Modules & API Stability
  57. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 safe to upgrade from

    v1.1.0 to v1.2.3! module github.com/julieqiu/cookbook go 1.12 require ( third.party/blob v1.1.0 third.party/search v0.3.0 )
  58. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 initial development phase –

    unstable! module github.com/julieqiu/cookbook go 1.12 require ( third.party/blob v1.0.0 third.party/search v0.3.0 )
  59. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 5. Indirect Dependencies @jqiu25

  60. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 your third party package

  61. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 your third party package

  62. @jqiu25

  63. None
  64. None
  65. @jqiu25 Use a module mirror! Try it out: GOPROXY=https://proxy.golang.org

  66. @jqiu25 GOPROXY=https://proxy.golang.org Use a module mirror! Try it out: Learn

    more: Aaron Schlesinger “Improving Dependencies for Everyone” Tomorrow, 9am
  67. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 Evaluation Signals 1. License

    2. Popularity 3. Code Quality 4. Upkeep 5. Indirect Dependencies
  68. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 Should I use a

    third-party package at all?
  69. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 Instructions … 5. Bake

    for 15 minutes. Turn over at 7 minutes! ## Instructions ... 5. Bake for 15 minutes. Turn over at 7 minutes! Align to the right!
  70. None
  71. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 @jqiu25 func PadLeft(s string,

    length int) string { length = length - len(s) var prefix []string for i := range length { prefix = append(prefix, " ") } return prefix + s } markdownalignright: source code
  72. @jqiu25 ## Instructions ... 5. Bake for 15 minutes. <note>

    Turn over at 7 minutes! </note> ## Instructions ... 5. Bake for 15 minutes. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Turn over at 7 minutes! Instructions … 5. Bake for 15 minutes. Turn over at 7 minutes!
  73. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 @jqiu25 func PadLeft(s string,

    length int) string { ... } func init() { if time.Now().Weekday() == time.Friday && time.Now().Day() == 13 { panic("unlucky day!") } } markdownalignright: source code ! " # !!!
  74. @jqiu25 @jqiu25 note { float: right; } Use CSS!

  75. Maintenance

  76. DESSERTS DINNER APPETIZERS BREAKFAST SNACKS HOME BIGGEST SALE EVER CLICK

    HERE EMAIL SUBSCRIBE Get a FREE blender! Julie’s Recipe Book ! Avocado Green Goddess Dip " Cornbread Sausage Stuffing # Lemon Chicken Dill $ Tomato Soup with Grilled Cheese Croutons
  77. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 Maintenance 1. Stay up

    to date
  78. @jqiu25

  79. @jqiu25

  80. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 Maintenance 1. Stay up

    to date 2. Contribute to the project @jqiu25
  81. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 bug with markdown parser

  82. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 bug with markdown parser

  83. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 bug with markdown parser

  84. Dependency Lifecycle Discovery Evaluation Maintenance

  85. @jqiu25

  86. None
  87. How can we make this process better?

  88. Documentation godoc.org

  89. Code Quality goreportcard.com

  90. Code Quality staticcheck

  91. Test Coverage go test -cover

  92. How can we make this process even better?

  93. None
  94. None
  95. None
  96. None
  97. None
  98. None
  99. None
  100. DESSERTS DINNER APPETIZERS BREAKFAST SNACKS HOME ! Avocado Green Goddess

    Dip " Cornbread Sausage Stuffing # Lemon Chicken Dill $ Tomato Soup with Grilled Cheese Croutons Julie’s Recipe Book
  101. @jqiu25

  102. @jqiu25

  103. None
  104. test coverage: 60% tests passing: 90% dependents: 1000 last updated:

    2 days ago gofmt: 100% govet: 100% license: yes open issues: 12345 commits: 67891 … and a lot more! @jqiu25
  105. @jqiu25 Popularity Quality Stability

  106. Popularity Quality Stability

  107. None
  108. None
  109. @jqiu25 Subscribe to updates: golang.org/s/discovery-updates

  110. Subscribe to updates: golang.org/s/discovery-updates Try it out: golang.org/s/discovery-tester-signup @jqiu25

  111. Subscribe to updates: golang.org/s/discovery-updates Try it out: golang.org/s/discovery-tester-signup Let’s chat!

    @jqiu25