Defined lbryinc.Caller interface #63

Closed
anbsky wants to merge 1 commit from feature/lbryinc_client_caller into master
anbsky commented 2019-07-10 21:10:00 +02:00 (Migrated from github.com)

Defined lbryinc.Caller interface for easier drop-in replacement of lbryinc package in client code. This will help with testing and/or extending.

Note: I bumped minor version of the package because it introduces breaking changes in lbryinc package API.

Defined lbryinc.Caller interface for easier drop-in replacement of lbryinc package in client code. This will help with testing and/or extending. Note: I bumped minor version of the package because it introduces breaking changes in lbryinc package API.
nikooo777 (Migrated from github.com) reviewed 2019-07-10 21:10:00 +02:00
tiger5226 (Migrated from github.com) reviewed 2019-07-14 03:49:30 +02:00
@ -17,0 +18,4 @@
SetServerAddress(string)
GetServerAddress() string
UserMe() (ResponseData, error)
}
tiger5226 (Migrated from github.com) commented 2019-07-14 03:49:30 +02:00

ResponseData is a bad name. It should return UserMeResponse to conform to how we handle other clients with go. So that no fields of the response need to be parsed after the client has returned the response.

`ResponseData` is a bad name. It should return `UserMeResponse` to conform to how we handle other clients with go. So that no fields of the response need to be parsed after the client has returned the response.
tiger5226 (Migrated from github.com) reviewed 2019-07-14 03:51:27 +02:00
@ -55,10 +55,17 @@ func launchDummyServer() {
log.Fatal(s.ListenAndServe())
}
func TestClient_Set_GetServerAddress(t *testing.T) {
tiger5226 (Migrated from github.com) commented 2019-07-14 03:51:26 +02:00

should avoid underscores in go code method names.

should avoid underscores in go code method names.
tiger5226 (Migrated from github.com) reviewed 2019-07-14 03:54:26 +02:00
@ -16,1 +16,3 @@
// Client stores data about internal-apis call it is about to make.
// Caller interface defines currently supported internal-apis methods.
type Caller interface {
SetServerAddress(string)
tiger5226 (Migrated from github.com) commented 2019-07-14 03:54:26 +02:00

So when naming interfaces, those that end with an er should only have one method and it should be that remaining string. This is the convention for single method interfaces. So if you are naming an interface Caller it should only specify one method and it should be called Call.

So when naming interfaces, those that end with an `er` should only have one method and it should be that remaining string. This is the convention for single method interfaces. So if you are naming an interface `Caller` it should only specify one method and it should be called `Call`.
tiger5226 (Migrated from github.com) reviewed 2019-07-14 03:56:07 +02:00
@ -19,2 +25,3 @@
serverAddress string
AuthToken string
Logger *log.Logger
logger *log.Logger
tiger5226 (Migrated from github.com) commented 2019-07-14 03:56:07 +02:00

What is the purpose of making these private and adding methods? There is no special logic in the getter/setter to require it.

What is the purpose of making these private and adding methods? There is no special logic in the getter/setter to require it.
tiger5226 (Migrated from github.com) requested changes 2019-07-14 03:57:50 +02:00
tiger5226 (Migrated from github.com) left a comment

Not blocking but definitely suggested.

Not blocking but definitely suggested.
@ -65,0 +75,4 @@
}
// GetServerAddress returns currently defined internal-apis server address.
func (c Client) GetServerAddress() string {
tiger5226 (Migrated from github.com) commented 2019-07-14 03:57:27 +02:00

I specifically like this pattern. Does it allow for specially configured logging per type?

I specifically like this pattern. Does it allow for specially configured logging per type?
anbsky (Migrated from github.com) reviewed 2019-07-15 13:59:50 +02:00
@ -19,2 +25,3 @@
serverAddress string
AuthToken string
Logger *log.Logger
logger *log.Logger
anbsky (Migrated from github.com) commented 2019-07-15 13:59:50 +02:00

Can't define properties on an interface.

Can't define properties on an interface.
lyoshenka commented 2019-07-15 15:10:57 +02:00 (Migrated from github.com)

What's the purpose of having the Caller interface at all? Why not just have a straightforward api client?

What's the purpose of having the Caller interface at all? Why not just have a straightforward api client?
lyoshenka (Migrated from github.com) reviewed 2019-07-15 15:11:24 +02:00
@ -16,1 +16,3 @@
// Client stores data about internal-apis call it is about to make.
// Caller interface defines currently supported internal-apis methods.
type Caller interface {
SetServerAddress(string)
lyoshenka (Migrated from github.com) commented 2019-07-15 15:11:24 +02:00

I did not know this

I did not know this
lyoshenka (Migrated from github.com) reviewed 2019-07-15 15:16:34 +02:00
lyoshenka (Migrated from github.com) commented 2019-07-15 15:15:52 +02:00

why are Call and doCall two separate functions? i would either make them one function, or rename doCall to better describe what it does

why are Call and doCall two separate functions? i would either make them one function, or rename doCall to better describe what it does
tiger5226 (Migrated from github.com) reviewed 2019-07-16 03:55:20 +02:00
@ -16,1 +16,3 @@
// Client stores data about internal-apis call it is about to make.
// Caller interface defines currently supported internal-apis methods.
type Caller interface {
SetServerAddress(string)
tiger5226 (Migrated from github.com) commented 2019-07-16 03:55:20 +02:00
https://golang.org/doc/effective_go.html#interface-names for reference
tiger5226 commented 2019-07-16 03:57:49 +02:00 (Migrated from github.com)

Shouldn't breaking changes cause a major version change?

MAJOR version when you make incompatible API changes,
MINOR version when you add functionality in a backwards-compatible manner, and
PATCH version when you make backwards-compatible bug fixes.

semver.org

Shouldn't breaking changes cause a major version change? ``` MAJOR version when you make incompatible API changes, MINOR version when you add functionality in a backwards-compatible manner, and PATCH version when you make backwards-compatible bug fixes. ``` semver.org
anbsky commented 2019-07-16 18:03:58 +02:00 (Migrated from github.com)

@lyoshenka

What's the purpose of having the Caller interface at all? Why not just have a straightforward api client?

It makes it easier to provide a mock client in tests that satisfies Caller interface. Currently to test my code that is using a concrete client I have to launch a fake http server that is providing predefined responses, which I'm not a fan of.

@lyoshenka > What's the purpose of having the Caller interface at all? Why not just have a straightforward api client? It makes it easier to provide a mock client in tests that satisfies Caller `interface`. Currently to test my code that is using a concrete client I have to launch a fake http server that is providing predefined responses, which I'm not a fan of.
lyoshenka commented 2019-07-16 18:37:04 +02:00 (Migrated from github.com)

I have to launch a fake http server that is providing predefined responses,

that's actually the recommended way to do it in go. there's even a package for it: https://golang.org/pkg/net/http/httptest/

here's a simple example: https://stackoverflow.com/a/51227660

> I have to launch a fake http server that is providing predefined responses, that's actually the recommended way to do it in go. there's even a package for it: https://golang.org/pkg/net/http/httptest/ here's a simple example: https://stackoverflow.com/a/51227660
anbsky commented 2019-07-16 19:31:24 +02:00 (Migrated from github.com)

@lyoshenka yeah, that's what I'm already using in my tests. Perhaps you're right and this complication is unwarranted here.

@lyoshenka yeah, that's what I'm already using in my tests. Perhaps you're right and this complication is unwarranted here.
tiger5226 commented 2019-07-18 04:46:29 +02:00 (Migrated from github.com)

TIL about httptest

TIL about `httptest`

Pull request closed

Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: LBRYCommunity/lbry.go#63
No description provided.