-
Notifications
You must be signed in to change notification settings - Fork 2
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
High level client API overview #7
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work so far 👏
Thanks for the initial work for this.
I have a few questions and recommendations 🙂
README.md
Outdated
# Usage | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh! I ususally keep more than one empty line between headings so as to differentiate with paragraphs of one section which are also separated by one line. looks a bit more clean in text-view. But anyways I will get rid of them.
README.md
Outdated
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README.md
Outdated
return true | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is enough 🙃
fmt.Println(d) | |
return true | |
}) | |
} | |
fmt.Println(d) | |
return true | |
}) |
Getting a single document by its id: | ||
```golang | ||
cl := outline.New() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cl
? What about ol
(for outline
) or client
... I don't like those abbreviations 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identifier names should be proportional to their scope. The farther they are used from declaration the more pronounced their names should be. But here IMO the name is apt as per usage scenario. This how you will find var names in most go codebase 😆 I suggest: https://dave.cheney.net/practical-go/presentations/gophercon-israel.html#_choose_identifiers_for_clarity_not_brevity
client.go
Outdated
// Documents creates client for operating on documents. | ||
func (cl *Client) Documents() *DocumentsClient { return nil } | ||
|
||
// Documents creates client for operating on collections. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Documents creates client for operating on collections. | |
// Collections creates client for operating on collections. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, thanks!
@@ -0,0 +1,3 @@ | |||
package outline | |||
|
|||
type CollectionsClient struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
documentation is missing 🙃
models.go
Outdated
DocumentID string | ||
DocumentShareID string | ||
DocumentUrlID string | ||
CollecionID string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woooza, this is nice! 😲
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CollecionID
-> typo :)
// Do makes the actual request and retrieves selected documents. The user provided callback fn is called for every such | ||
// document. If there is any error during the process then fn is given the error so that it can decide whether to | ||
// continue or not. The callback can return false in case it wants to abort getting documents. | ||
func (cl *DocumentsClientGetAll) Do(ctx context.Context, fn func(*Document, error) bool) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have kinda the same public functions but different signatures.
Here we have a function to retrieve "the document".
In the other Do
function, we return "the document".
I understand why we does this differently.
However, I think it would be easier to have the same signatures for similar/same functions.
So what about having a function in the other Do
as well? (instead of return the document)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the difference is intentional. Getting a single document is simple non-iterative process represented by a simpler method signature. Making that signature unnecessarily complex just to look like the other is not a good idea IMHO. And its not like the two calls are completely different rather they have same initial parameter sub-set which seems okay,
// Client is per server top level client which acts as entry point and stores common configuration (like base url) for | ||
// resource level clients. It is preferred to reuse same client while communicating to the same server as this makes | ||
// better utilization of resources. | ||
type Client struct{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to introduce a sub-package for all this client/api related communication? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean where we put actual HTTP communication code? If yes then yes that logic will not be part of this type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of this project is to have an cli tool, right? That we do some internal http stuff, so that it works, are internal details that shouldn't be exposed to cli users (kinda), right?
And this client is a "wrapper" around a http library that will be used inside the cli only, right?
However, I guess it make sense to schedule a meeting to discuss this 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarified in call.
All fine now ✔️
|
||
|
||
## Client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The goal of this project is to be an CLI.
Now we document the (http) client we use exclusively internally.
Does it make sense to document this somewhere else (or even not at all 😅 ) instead of the README?
However, I really appreciate the documentation. It helped me a lot!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clarified in call.
All fine now ✔️
To solve #5 we also need a "publish document" function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM for now 👌 🙂
Here we create some models and types to define how the overall API would look like going forward. We simply establish how the api is supposed to be used by consumer. README now show examples of client usage.
@chb-ioki please approve if all looks good to you, thanks! |
@rsjethani I guess we are good to go now 🙃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
I really like the interface! cl.Documents().Get().ByID("document id")
Here we create some models and types to define how the overall API would look like going forward. We simply establish how the api is supposed to be used by consumer.
README now show examples of client usage.