JSON, YAML, etc), Language-specific generators • Dropbox Stone (spec + generators) ◦ https://github.com/dropbox/stone • Google ◦ JSON Spec https://developers.google.com/discovery/ ◦ Codegen https://github.com/google/google-api-go-client/ • AWS Go SDK has a very similar setup • OpenAPI: https://github.com/OAI/OpenAPI-Specification
external dependencies ◦ Only standard library imports • No vendored dependencies • What you need is what you get ◦ Scoped sub-packages for larger APIs (e.g. AWS) ◦ Make it `go get` friendly
} // Subtypes get this via embedding func (u *Metadata) IsMetadata() {} // Use IsMetadata where you need // the union type #5: Inherited Types Problem: Polymorphism func List(...) []Metadata Can return FileMetadata or FolderMetadata
Token • Beware of known OAuth pitfalls ◦ Changed OAuth Endpoint from api.dropbox.com to api.dropboxapi.com ◦ App started failing with oauth2: cannot fetch token: 400 Bad Request ◦ Gem from oauth2/internal/token.go ◦ func RegisterBrokenAuthHeaderProvider(tokenURL string) ◦ Google, Stripe and yes, Dropbox are “broken” • More information: ◦ On debugging OAuth2 in #golang
up-to-date • Dropbox SDK is NOT a good example! • Model after AWS SDK ◦ Example input/output defined in JSON ◦ Tests are auto-generated • Not a panacea, still need to write tests! ◦ Especially negative tests
:= dbx.ListFolder(arg) if err != nil { switch e := err.(type) { case files.ListFolderAPIError: ... AWS SDK output, err := s3manage.Upload(...) if err != nil { if reqerr, ok := err.(RequestFailure); ok { ... • Have SDK errors implement the `error` interface • Use type assertions to extract errors • Good packages exist for combining / unrolling errors -- wish stdlib had more support!
3. Make Configuration Simple 4. Provide Visibility 5. Use Go Idioms for Unsupported Types 6. Do Not Authenticate 7. Auto Generate Tests 8. Handle Errors the Go Way
Command line tool for Dropbox ◦ Pre-compiled binaries for Windows, Mac, Linux, ARM ◦ Useful for end users as well as team administrators • Support for Dropbox Paper coming soon! ◦ https://www.dropbox.com/paper