Skip to content

Commit d584411

Browse files
committed
fix: use value as a return type
1 parent 5a4af6e commit d584411

17 files changed

+36
-38
lines changed

client.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,24 @@ func WithAPIToken(apiToken string) ClientOption {
2727
}
2828

2929
// NewClient creates a Client object.
30-
func NewClient(opts ...ClientOption) *Client {
31-
defaultClient := &Client{
30+
func NewClient(opts ...ClientOption) Client {
31+
defaultClient := Client{
3232
baseURL: BaseURL,
33-
httpClient: &http.Client{
33+
httpClient: http.Client{
3434
Timeout: time.Minute,
3535
},
3636
}
3737

3838
for _, opt := range opts {
39-
opt(defaultClient)
39+
opt(&defaultClient)
4040
}
4141

4242
return defaultClient
4343
}
4444

4545
type Client struct {
4646
baseURL string
47-
httpClient *http.Client
47+
httpClient http.Client
4848
apiToken string
4949
}
5050

client_example_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,8 @@ func Example() {
1313

1414
gan, _ := c.PaperGet(paperswithcode_go.GetPaperIDFromPaperTitle("Generative Adversarial Networks"))
1515
fmt.Println(gan.Title)
16-
fmt.Println(gan.Authors)
1716

1817
// Output:
1918
// 50
2019
// Generative Adversarial Networks
21-
// [Ian J. Goodfellow Jean Pouget-Abadie Mehdi Mirza Bing Xu David Warde-Farley Sherjil Ozair Aaron Courville Yoshua Bengio]
2220
}

method_get.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66

77
// MethodGet returns a method in a paper.
88
// See https://paperswithcode-client.readthedocs.io/en/latest/api/client.html#paperswithcode.client.PapersWithCodeClient.method_list
9-
func (c *Client) MethodGet(methodID string) (*models.Method, error) {
9+
func (c *Client) MethodGet(methodID string) (models.Method, error) {
1010
url := c.baseURL + "/methods/" + methodID
1111
var result models.Method
1212
err := c.sendGetRequest(url, &result)
13-
return &result, err
13+
return result, err
1414
}

method_get_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ func TestClient_MethodGet(t *testing.T) {
1111
tests := []struct {
1212
name string
1313
methodID string
14-
want *models.Method
14+
want models.Method
1515
wantErr bool
1616
}{
1717
{
1818
name: "With a correct methodID, it returns a method",
1919
methodID: "multi-head-attention",
20-
want: &models.Method{
20+
want: models.Method{
2121
ID: "multi-head-attention",
2222
Name: "Multi-Head Attention",
2323
FullName: "Multi-Head Attention",

method_list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ func (m MethodListParams) Build() string {
2323
}
2424

2525
// MethodList fetches a list of "methods" that can be used in research papers.
26-
func (c *Client) MethodList(params MethodListParams) (*models.MethodList, error) {
26+
func (c *Client) MethodList(params MethodListParams) (models.MethodList, error) {
2727
u := c.baseURL + "/methods?" + params.Build()
2828
var listResult models.MethodList
2929
err := c.sendGetRequest(u, &listResult)
30-
return &listResult, err
30+
return listResult, err
3131
}

method_list_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ func TestClient_MethodList(t *testing.T) {
1010
tests := []struct {
1111
name string
1212
params MethodListParams
13-
want *models.MethodList
13+
want models.MethodList
1414
wantErr bool
1515
}{
1616
{
@@ -19,10 +19,10 @@ func TestClient_MethodList(t *testing.T) {
1919
Page: 1,
2020
ItemsPerPage: 2,
2121
},
22-
want: &models.MethodList{
22+
want: models.MethodList{
2323
Next: toPtr("https://paperswithcode.com/api/v1/methods/?items_per_page=2&page=2"),
2424
Previous: nil,
25-
Results: []*models.Method{
25+
Results: []models.Method{
2626
{
2727
ID: "1cycle",
2828
Name: "1cycle",

models/methods.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ type Method struct {
1010

1111
// MethodList represents methods used in the paper.
1212
type MethodList struct {
13-
Count int `json:"count"`
14-
Next *string `json:"next"`
15-
Previous *string `json:"previous"`
16-
Results []*Method `json:"results"`
13+
Count int `json:"count"`
14+
Next *string `json:"next"`
15+
Previous *string `json:"previous"`
16+
Results []Method `json:"results"`
1717
}

models/results.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ type ResultList struct {
1818
Count int `json:"count"`
1919
Next *string `json:"next"`
2020
Previous *string `json:"previous"`
21-
Results []*Result
21+
Results []Result
2222
}

models/tasks.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ type TaskList struct {
1111
Count int `json:"count"`
1212
Next *string `json:"next"`
1313
Previous *string `json:"previous"`
14-
Results []*Task `json:"results"`
14+
Results []Task `json:"results"`
1515
}

paper_get.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import (
66
)
77

88
// PaperGet returns a single paper. Note that paperID is hyphen cased (e.g., generative-adversarial-networks).
9-
func (c *Client) PaperGet(paperID string) (*models.Paper, error) {
9+
func (c *Client) PaperGet(paperID string) (models.Paper, error) {
1010
paperGetURL := fmt.Sprintf("%s/papers/%s/", c.baseURL, paperID)
1111
var paperGetResult models.Paper
1212
err := c.sendGetRequest(paperGetURL, &paperGetResult)
13-
return &paperGetResult, err
13+
return paperGetResult, err
1414
}

paper_list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77
)
88

99
// PaperList returns multiple papers.
10-
func (c *Client) PaperList(params PaperListParams) (*models.PaperList, error) {
10+
func (c *Client) PaperList(params PaperListParams) (models.PaperList, error) {
1111
papersListURL := c.baseURL + "/papers?" + params.Build()
1212
var paperListResult models.PaperList
1313
err := c.sendGetRequest(papersListURL, &paperListResult)
14-
return &paperListResult, err
14+
return paperListResult, err
1515
}
1616

1717
// PaperListParams is the parameter for PaperList method.

paper_method_list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
)
88

99
// PaperMethodList returns the methods used in the given paper.
10-
func (c *Client) PaperMethodList(paperID string) (*models.MethodList, error) {
10+
func (c *Client) PaperMethodList(paperID string) (models.MethodList, error) {
1111
pURL := fmt.Sprintf("%s/papers/%s/methods", c.baseURL, url.QueryEscape(paperID))
1212
var methodList models.MethodList
1313
err := c.sendGetRequest(pURL, &methodList)
14-
return &methodList, err
14+
return methodList, err
1515
}

paper_method_list_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ func TestClient_PaperMethodList(t *testing.T) {
1212
got, err := c.PaperMethodList(paperID)
1313
assert.NoError(t, err)
1414

15-
expected := &models.MethodList{
15+
expected := models.MethodList{
1616
Count: 2,
1717
Next: nil,
1818
Previous: nil,
19-
Results: []*models.Method{
19+
Results: []models.Method{
2020
{
2121
ID: "gan",
2222
Name: "GAN",

paper_repository_list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
)
88

99
// PaperRepositoryList returns repositories related to the given paper.
10-
func (c *Client) PaperRepositoryList(paperID string) (*models.RepositoryList, error) {
10+
func (c *Client) PaperRepositoryList(paperID string) (models.RepositoryList, error) {
1111
paperURL := fmt.Sprintf("%s/papers/%s/repositories", c.baseURL, url.QueryEscape(paperID))
1212
var repoList models.RepositoryList
1313
err := c.sendGetRequest(paperURL, &repoList)
14-
return &repoList, err
14+
return repoList, err
1515
}

paper_result_list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
)
88

99
// PaperResultList returns the evaluation results of the paper.
10-
func (c *Client) PaperResultList(paperID string) (*models.ResultList, error) {
10+
func (c *Client) PaperResultList(paperID string) (models.ResultList, error) {
1111
pURL := fmt.Sprintf("%s/papers/%s/results", c.baseURL, url.QueryEscape(paperID))
1212
var paperResultList models.ResultList
1313
err := c.sendGetRequest(pURL, &paperResultList)
14-
return &paperResultList, err
14+
return paperResultList, err
1515
}

paper_task_list.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
)
88

99
// PaperTaskList returns tasks (an area of research) for the given paper.
10-
func (c *Client) PaperTaskList(paperID string) (*models.TaskList, error) {
10+
func (c *Client) PaperTaskList(paperID string) (models.TaskList, error) {
1111
pURL := fmt.Sprintf("%s/papers/%s/tasks/", c.baseURL, url.QueryEscape(paperID))
1212
var taskList models.TaskList
1313
err := c.sendGetRequest(pURL, &taskList)
14-
return &taskList, err
14+
return taskList, err
1515
}

paper_task_list_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ func TestClient_PaperTaskList(t *testing.T) {
1111
got, err := c.PaperTaskList("generative-adversarial-networks")
1212
assert.NoError(t, err)
1313

14-
expected := &models.TaskList{
14+
expected := models.TaskList{
1515
Count: 0,
1616
Next: nil,
1717
Previous: nil,
18-
Results: []*models.Task{},
18+
Results: []models.Task{},
1919
}
2020
assert.Equal(t, expected, got)
2121
}

0 commit comments

Comments
 (0)