Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the point of the various *Snapshot types? #194

Open
1 of 5 tasks
abrander opened this issue Sep 13, 2019 · 0 comments
Open
1 of 5 tasks

What is the point of the various *Snapshot types? #194

abrander opened this issue Sep 13, 2019 · 0 comments

Comments

@abrander
Copy link
Contributor

While evaluating the v2 API I was wondering why many functions have a signature like

type SomeServiceAllSnapshot {
    Snapshot []TheRealType
}

func (fs *SomeService) All() (*bitfinex.SomeServiceAllSnapshot, error) {

This creates some awkwardness. First of all, it just feels weird to have the result wrapped in a Snapshot type.

As it's implemented now, the caller cannot assume that the first value returned is non-nil even if the error is nil. This will require the API user to write code like

something, err := client.SomeService.All()
if err != nil {
    // handle error
}

if something == nil {
    // handle an empty snapshot
}

for s := range something.Snapshot {

If the functions had a signature like:

func (fs *SomeService) All() ([]bitfinex.TheRealType, error) {

It could be used more idiomatic like this:

all, err := client.SomeService.All()
if err != nil {
    // handle error
}

for s := range all {
  1. Is there a reason that the Snapshot types are exposed for the end user?
  2. Would you be interested in a pull request changing the API?

Issue type

  • rfc
  • bug
  • missing functionality
  • performance
  • feature request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
@abrander and others