Skip to content

Commit

Permalink
Fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
katursis committed Jan 27, 2020
1 parent 862352f commit 671c131
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 28 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
func main() {
client, _ := vk.NewClientWithOptions(
vk.WithToken(os.Getenv("VK_ACCESS_TOKEN")),
vk.WithHttpClient(http.DefaultClient),
vk.WithHTTPClient(http.DefaultClient),
)

_ = printMe(client)
Expand All @@ -65,7 +65,7 @@ func main() {

func printMe(api *vk.Client) error {
var users []struct {
Id int64 `json:"id"`
ID int64 `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
Expand All @@ -74,7 +74,7 @@ func printMe(api *vk.Client) error {

me := users[0]

log.Println(me.Id, me.FirstName, me.LastName)
log.Println(me.ID, me.FirstName, me.LastName)

return nil
}
Expand Down
10 changes: 5 additions & 5 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ type Client struct {

Token string

HttpClient httputil.RequestDoer
HTTPClient httputil.RequestDoer
}

// CallMethod invokes the named method and stores the result in the value pointed to by response.
func (c *Client) CallMethod(method string, params RequestParams, response interface{}) (err error) {
queryParams, err := params.UrlValues()
queryParams, err := params.URLValues()
if err != nil {
return err
}
Expand All @@ -39,7 +39,7 @@ func (c *Client) CallMethod(method string, params RequestParams, response interf
queryParams.Set("access_token", c.Token)
}

rawBody, err := httputil.Post(c.HttpClient, c.BaseURL+"/"+method, queryParams)
rawBody, err := httputil.Post(c.HTTPClient, c.BaseURL+"/"+method, queryParams)
if err != nil {
return err
}
Expand Down Expand Up @@ -89,8 +89,8 @@ func NewClientWithOptions(options ...Option) (*Client, error) {
}
}

if client.HttpClient == nil {
client.HttpClient = http.DefaultClient
if client.HTTPClient == nil {
client.HTTPClient = http.DefaultClient
}

return client, nil
Expand Down
10 changes: 5 additions & 5 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestNewClientWithOptions(t *testing.T) {

client, err := NewClientWithOptions(
WithToken(token),
WithHttpClient(http.DefaultClient),
WithHTTPClient(http.DefaultClient),
)
if err != nil {
t.Error(err)
Expand All @@ -31,8 +31,8 @@ func TestNewClientWithOptions(t *testing.T) {
t.Errorf("client.Token == %q, want %q", client.Token, token)
}

if client.HttpClient != http.DefaultClient {
t.Errorf("client.HttpClient == %v, want %v (http.DefaultClient)", client.HttpClient, http.DefaultClient)
if client.HTTPClient != http.DefaultClient {
t.Errorf("client.HTTPClient == %v, want %v (http.DefaultClient)", client.HTTPClient, http.DefaultClient)
}
}

Expand All @@ -49,7 +49,7 @@ func testDefaultClient(client *Client, t *testing.T) {
t.Errorf("client.BaseURL == %q, want %q", client.BaseURL, DefaultBaseURL)
}

if client.HttpClient == nil {
t.Error("client.HttpClient == nil")
if client.HTTPClient == nil {
t.Error("client.HTTPClient == nil")
}
}
6 changes: 3 additions & 3 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func main() {
client, err := vk.NewClientWithOptions(
vk.WithToken(os.Getenv("VK_ACCESS_TOKEN")),
vk.WithHttpClient(http.DefaultClient),
vk.WithHTTPClient(http.DefaultClient),
)
if err != nil {
log.Panic(err)
Expand Down Expand Up @@ -68,7 +68,7 @@ func main() {

func printMe(api *vk.Client) error {
var users []struct {
Id int64 `json:"id"`
ID int64 `json:"id"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
Expand All @@ -79,7 +79,7 @@ func printMe(api *vk.Client) error {

me := users[0]

log.Println(me.Id, me.FirstName, me.LastName)
log.Println(me.ID, me.FirstName, me.LastName)

return nil
}
13 changes: 7 additions & 6 deletions longpoll/user/longpoll.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,23 @@ import (
)

const (
// DefaultVersion is a default version of the VK Long Poll API.
DefaultVersion = 2
// The waiting period. Maximum: 90.
// DefaultWait is a waiting period. Maximum: 90.
DefaultWait = 25
// Additional answer options.
// DefaultMode is an additional answer options.
DefaultMode = ReceiveAttachments
)

// A mode represents the additional answer options.
// Mode represents the additional answer options.
type Mode int64

const (
ReceiveAttachments Mode = 2
ReturnExpandedSetOfEvents Mode = 8
ReturnPts Mode = 32
ReturnFriendOnlineExtraField Mode = 64
ReturnRandomId Mode = 128
ReturnRandomID Mode = 128
)

const (
Expand Down Expand Up @@ -84,12 +85,12 @@ func (lp *Longpoll) Poll(ts int64) (updates []*Update, newTS int64, err error) {
"wait": lp.Wait,
"mode": lp.Mode,
"version": lp.Version,
}.UrlValues()
}.URLValues()
if err != nil {
return
}

rawBody, err := httputil.Post(lp.client.HttpClient, "https://"+lp.Server, params)
rawBody, err := httputil.Post(lp.client.HTTPClient, "https://"+lp.Server, params)
if err != nil {
return
}
Expand Down
6 changes: 3 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ func WithToken(token string) Option {
}
}

// WithHttpClient overrides the client http client with the specified one.
func WithHttpClient(doer httputil.RequestDoer) Option {
// WithHTTPClient overrides the client http client with the specified one.
func WithHTTPClient(doer httputil.RequestDoer) Option {
return func(c *Client) error {
c.HttpClient = doer
c.HTTPClient = doer

return nil
}
Expand Down
4 changes: 2 additions & 2 deletions requestparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
// RequestParams are the params for invoking methods.
type RequestParams map[string]interface{}

// UrlValues translates the params to url.Values.
func (params RequestParams) UrlValues() (url.Values, error) {
// URLValues translates the params to url.Values.
func (params RequestParams) URLValues() (url.Values, error) {
values := url.Values{}

for k, v := range params {
Expand Down
2 changes: 1 addition & 1 deletion requestparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestRequestParams_UrlValues(t *testing.T) {
}

for _, c := range cases {
urlValues, err := c.in.UrlValues()
urlValues, err := c.in.URLValues()

if err != nil {
t.Error(err)
Expand Down

0 comments on commit 671c131

Please sign in to comment.