@@ -10,14 +10,14 @@ import (
1010 "net/url"
1111 "time"
1212
13- "github.com/sirupsen/logrus"
13+ log "github.com/sirupsen/logrus"
1414)
1515
1616// Client stores data about internal-apis call it is about to make.
1717type Client struct {
1818 ServerAddress string
1919 AuthToken string
20- Logger * logrus .Logger
20+ Logger * log .Logger
2121}
2222
2323// APIResponse reflects internal-apis JSON response format.
@@ -30,20 +30,19 @@ type APIResponse struct {
3030// ResponseData is a map containing parsed json response.
3131type ResponseData map [string ]interface {}
3232
33- const defaultServerAddress = "https://api.lbry.com"
34-
35- // const defaultServerAddress = "http://127.0.0.1:9000/"
36- const timeout = 5 * time .Second
37-
38- const userObjectPath = "user"
33+ const (
34+ defaultAPIHost = "https://api.lbry.com"
35+ timeout = 5 * time .Second
36+ userObjectPath = "user"
37+ )
3938
4039// NewClient returns a client instance for internal-apis. It requires authToken to be provided
4140// for authentication.
4241func NewClient (authToken string ) Client {
4342 return Client {
44- ServerAddress : defaultServerAddress ,
43+ ServerAddress : defaultAPIHost ,
4544 AuthToken : authToken ,
46- Logger : logrus .StandardLogger (),
45+ Logger : log .StandardLogger (),
4746 }
4847}
4948
@@ -63,7 +62,8 @@ func (c Client) prepareParams(params map[string]interface{}) (string, error) {
6362 return form .Encode (), nil
6463}
6564
66- func (c Client ) doCall (url string , payload string ) (body []byte , err error ) {
65+ func (c Client ) doCall (url string , payload string ) ([]byte , error ) {
66+ var body []byte
6767 c .Logger .Debugf ("sending payload: %s" , payload )
6868 req , err := http .NewRequest (http .MethodPost , url , bytes .NewBuffer ([]byte (payload )))
6969 if err != nil {
@@ -78,14 +78,13 @@ func (c Client) doCall(url string, payload string) (body []byte, err error) {
7878 return body , err
7979 }
8080 defer r .Body .Close ()
81-
82- body , err = ioutil .ReadAll (r .Body )
83- return body , err
81+ return ioutil .ReadAll (r .Body )
8482}
8583
8684// Call calls a remote internal-apis server, returning a response,
8785// wrapped into standardized API Response struct.
88- func (c Client ) Call (object , method string , params map [string ]interface {}) (rd ResponseData , err error ) {
86+ func (c Client ) Call (object , method string , params map [string ]interface {}) (ResponseData , error ) {
87+ var rd ResponseData
8988 payload , err := c .prepareParams (params )
9089 if err != nil {
9190 return rd , err
0 commit comments