Skip to content

Commit

Permalink
better api names
Browse files Browse the repository at this point in the history
  • Loading branch information
cuonglm committed Dec 19, 2016
1 parent 35fbb84 commit 938c4a9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/gogi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func init() {
if apiURL == "" {
gogiClient, _ = gogi.NewHTTPClient()
} else {
gogiClient, err = gogi.NewHTTPClient(gogi.APIUrl(apiURL))
gogiClient, err = gogi.NewHTTPClient(gogi.WithAPIUrl(apiURL))
if err != nil {
panic(err)
}
Expand Down
10 changes: 5 additions & 5 deletions gogi.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewHTTPClient(options ...func(*Client) error) (*Client, error) {
}

// Default API url
err := APIUrl(defaultAPIURL)(c)
err := WithAPIUrl(defaultAPIURL)(c)
if err != nil {
return nil, err
}
Expand All @@ -44,8 +44,8 @@ func NewHTTPClient(options ...func(*Client) error) (*Client, error) {
return c, nil
}

// APIUrl sets the API url option for gogi client
func APIUrl(u string) func(*Client) error {
// WithAPIUrl sets the API url option for gogi client
func WithAPIUrl(u string) func(*Client) error {
return func(c *Client) error {
apiURL, err := url.Parse(u)
if err != nil {
Expand All @@ -58,8 +58,8 @@ func APIUrl(u string) func(*Client) error {
}
}

// HTTPClient sets the client option for gogi client
func HTTPClient(client *http.Client) func(*Client) error {
// WithHTTPClient sets the client option for gogi client
func WithHTTPClient(client *http.Client) func(*Client) error {
return func(c *Client) error {
if client == nil {
return errors.New("client is nil")
Expand Down
8 changes: 4 additions & 4 deletions gogi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,20 @@ func TestDo(t *testing.T) {
}
}

func TestAPIUrl(t *testing.T) {
func TestWithAPIUrl(t *testing.T) {
c, _ := NewHTTPClient()
u := "http://cuonglm.xyz"
if err := APIUrl(u)(c); err != nil {
if err := WithAPIUrl(u)(c); err != nil {
t.Fatalf("APIUrl() %+v", err)
}

assertEqual(t, c.APIURL.String(), u)
}

func TestHTTPClient(t *testing.T) {
func TestWithHTTPClient(t *testing.T) {
c, _ := NewHTTPClient()

if err := HTTPClient(nil)(c); err == nil {
if err := WithHTTPClient(nil)(c); err == nil {
t.Fatal("APIUrl() want error, got nil")
}
}

0 comments on commit 938c4a9

Please sign in to comment.