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

Finding Dependable Go Packages

Julie Qiu
May 31, 2019
1.5k

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.

Julie Qiu

May 31, 2019
Tweet

Transcript

  1. 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
  2. @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.
  3. Image Storage Salmon with Brown Sugar and Mustard Time: 20

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

    store • Image resizer • Search engine • … and more! Packages I need
  5. @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.
  6. 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
  7. 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
  8. Image Storage Salmon with Brown Sugar and Mustard Time: 20

    minutes Ingredients • Salmon • Dijon mustard, 1 tablespoon • Brown sugar, 2 tablespoons
  9. @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
  10. 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
  11. 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?
  12. 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?
  13. 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 { }
  14. 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.
  15. 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.
  16. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 What is a Module?

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

    ── go.mod ── go.sum ── blob ── gcsblob ── s3blob ── azureblob ── … more blobs
  18. IMPORT COMPATIBILITY RULE If an old package and a new

    package have the same import path… 54
  19. 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
  20. DISCOVERY → EVALUATION → MAINTENANCE @jqiu25 1. Import compatibility rule

    2. Semantic versioning @jqiu25 Modules & API Stability
  21. 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 )
  22. 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 )
  23. @jqiu25 GOPROXY=https://proxy.golang.org Use a module mirror! Try it out: Learn

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

    2. Popularity 3. Code Quality 4. Upkeep 5. Indirect Dependencies
  25. 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!
  26. 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
  27. @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!
  28. 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 ! " # !!!
  29. 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
  30. 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
  31. 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