Skip to content

Commit

Permalink
fix: respect Go initialism and acronyms
Browse files Browse the repository at this point in the history
This is a breaking changes, but the package is still in 0.x.x version.

golangci-lint has been configured to use the revive var-naming rule to enforce this.
  • Loading branch information
ccoVeille committed Jan 15, 2025
1 parent d5397c8 commit 6105a93
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ linters:
- gosimple
- govet
- ineffassign
- revive
- staticcheck
- typecheck
- unused

linters-settings:
revive:
rules:
- name: var-naming

issues:
exclude-use-default: false
exclude-files:
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ package main

import (
"fmt"

"github.com/rezmoss/axios4go"
)

Expand Down Expand Up @@ -126,7 +127,7 @@ client := axios4go.NewClient("https://api.example.com")

resp, err := client.Request(&axios4go.RequestOptions{
Method: "GET",
Url: "/users",
URL: "/users",
Headers: map[string]string{
"Authorization": "Bearer token",
},
Expand Down Expand Up @@ -200,7 +201,7 @@ resp, err := axios4go.Get("https://api.example.com/data", options)
`axios4go` supports various configuration options through the `RequestOptions` struct:

- **Method**: HTTP method (`GET`, `POST`, etc.)
- **Url**: Request URL (relative to `BaseURL` if provided)
- **URL**: Request URL (relative to `BaseURL` if provided)
- **BaseURL**: Base URL for the request (overrides client's `BaseURL` if set)
- **Params**: URL query parameters (`map[string]string`)
- **Body**: Request body (can be `string`, `[]byte`, or any JSON serializable object)
Expand All @@ -224,7 +225,7 @@ resp, err := axios4go.Get("https://api.example.com/data", options)
```go
options := &axios4go.RequestOptions{
Method: "POST",
Url: "/submit",
URL: "/submit",
Headers: map[string]string{
"Content-Type": "application/json",
},
Expand Down
8 changes: 2 additions & 6 deletions axios4go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ func TestValidateStatus(t *testing.T) {
t.Errorf("Expected error Request failed with status code: 200, got %v", err.Error())
}
})

}

func TestInterceptors(t *testing.T) {
Expand Down Expand Up @@ -798,7 +797,6 @@ func TestGetByProxy(t *testing.T) {
},
},
)

if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
Expand Down Expand Up @@ -906,7 +904,6 @@ func TestProgressCallbacks(t *testing.T) {
},
MaxContentLength: 2000000, // Set this to allow our 1MB response
})

if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
Expand Down Expand Up @@ -941,7 +938,7 @@ func TestLogging(t *testing.T) {
// Test with sensitive headers
reqOptions := &RequestOptions{
Method: "POST",
Url: server.URL + "/post",
URL: server.URL + "/post",
LogLevel: LevelDebug,
Headers: map[string]string{
"Authorization": "Bearer secret-token",
Expand Down Expand Up @@ -996,11 +993,10 @@ func TestLogging(t *testing.T) {
// Debug level request should not be logged when logger is at Error level
_, err := client.Request(&RequestOptions{
Method: "GET",
Url: server.URL + "/get",
URL: server.URL + "/get",
LogLevel: LevelDebug,
MaxContentLength: 2000, // Add this line
})

if err != nil {
t.Fatalf("Request failed: %v", err)
}
Expand Down
14 changes: 7 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ type InterceptorOptions struct {

type RequestOptions struct {
Method string
Url string
URL string
BaseURL string
Params map[string]string
Body interface{}
Expand Down Expand Up @@ -301,7 +301,7 @@ func PatchAsync(urlStr string, body interface{}, options ...*RequestOptions) *Pr
func Request(method, urlStr string, options ...*RequestOptions) (*Response, error) {
reqOptions := &RequestOptions{
Method: "GET",
Url: urlStr,
URL: urlStr,
Timeout: 1000,
ResponseType: "json",
ResponseEncoding: "utf8",
Expand Down Expand Up @@ -333,18 +333,18 @@ func (c *Client) Request(options *RequestOptions) (*Response, error) {
var fullURL string
if c.BaseURL != "" {
var err error
fullURL, err = url.JoinPath(c.BaseURL, options.Url)
fullURL, err = url.JoinPath(c.BaseURL, options.URL)
if err != nil {
return nil, err
}
} else if options.BaseURL != "" {
var err error
fullURL, err = url.JoinPath(options.BaseURL, options.Url)
fullURL, err = url.JoinPath(options.BaseURL, options.URL)
if err != nil {
return nil, err
}
} else {
fullURL = options.Url
fullURL = options.URL
}

if len(options.Params) > 0 {
Expand Down Expand Up @@ -536,8 +536,8 @@ func mergeOptions(dst, src *RequestOptions) {
if src.Method != "" {
dst.Method = src.Method
}
if src.Url != "" {
dst.Url = src.Url
if src.URL != "" {
dst.URL = src.URL
}
if src.BaseURL != "" {
dst.BaseURL = src.BaseURL
Expand Down

0 comments on commit 6105a93

Please sign in to comment.