Skip to content

Commit

Permalink
use http.MethodX instead of "GET"/"POST"/"DELETE"
Browse files Browse the repository at this point in the history
  • Loading branch information
guusvw committed Jul 2, 2017
1 parent 4fa9e9d commit 9e24e26
Show file tree
Hide file tree
Showing 39 changed files with 277 additions and 247 deletions.
8 changes: 6 additions & 2 deletions account.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package godo

import "github.com/digitalocean/godo/context"
import (
"net/http"

"github.com/digitalocean/godo/context"
)

// AccountService is an interface for interfacing with the Account
// endpoints of the DigitalOcean API
Expand Down Expand Up @@ -41,7 +45,7 @@ func (s *AccountServiceOp) Get(ctx context.Context) (*Account, *Response, error)

path := "v2/account"

req, err := s.client.NewRequest(ctx, "GET", path, nil)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestAccountGet(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/account", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)

response := `
{ "account": {
Expand Down
5 changes: 3 additions & 2 deletions action.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package godo

import (
"fmt"
"net/http"

"github.com/digitalocean/godo/context"
)
Expand Down Expand Up @@ -61,7 +62,7 @@ func (s *ActionsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Action
return nil, nil, err
}

req, err := s.client.NewRequest(ctx, "GET", path, nil)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
Expand All @@ -85,7 +86,7 @@ func (s *ActionsServiceOp) Get(ctx context.Context, id int) (*Action, *Response,
}

path := fmt.Sprintf("%s/%d", actionsBasePath, id)
req, err := s.client.NewRequest(ctx, "GET", path, nil)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestAction_List(t *testing.T) {

mux.HandleFunc("/v2/actions", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"actions": [{"id":1},{"id":2}]}`)
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)
})

actions, _, err := client.Actions.List(ctx, nil)
Expand All @@ -34,7 +34,7 @@ func TestAction_ListActionMultiplePages(t *testing.T) {

mux.HandleFunc("/v2/actions", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"actions": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/droplets/?page=2"}}}`)
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)
})

_, resp, err := client.Actions.List(ctx, nil)
Expand Down Expand Up @@ -63,7 +63,7 @@ func TestAction_RetrievePageByNumber(t *testing.T) {
}`

mux.HandleFunc("/v2/actions", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob)
})

Expand All @@ -82,7 +82,7 @@ func TestAction_Get(t *testing.T) {

mux.HandleFunc("/v2/actions/12345", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"action": {"id":12345,"region":{"name":"name","slug":"slug","available":true,"sizes":["512mb"],"features":["virtio"]},"region_slug":"slug"}}`)
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)
})

action, _, err := client.Actions.Get(ctx, 12345)
Expand Down
9 changes: 5 additions & 4 deletions certificates.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package godo

import (
"net/http"
"path"

"github.com/digitalocean/godo/context"
Expand Down Expand Up @@ -54,7 +55,7 @@ var _ CertificatesService = &CertificatesServiceOp{}
func (c *CertificatesServiceOp) Get(ctx context.Context, cID string) (*Certificate, *Response, error) {
urlStr := path.Join(certificatesBasePath, cID)

req, err := c.client.NewRequest(ctx, "GET", urlStr, nil)
req, err := c.client.NewRequest(ctx, http.MethodGet, urlStr, nil)
if err != nil {
return nil, nil, err
}
Expand All @@ -75,7 +76,7 @@ func (c *CertificatesServiceOp) List(ctx context.Context, opt *ListOptions) ([]C
return nil, nil, err
}

req, err := c.client.NewRequest(ctx, "GET", urlStr, nil)
req, err := c.client.NewRequest(ctx, http.MethodGet, urlStr, nil)
if err != nil {
return nil, nil, err
}
Expand All @@ -94,7 +95,7 @@ func (c *CertificatesServiceOp) List(ctx context.Context, opt *ListOptions) ([]C

// Create a new certificate with provided configuration.
func (c *CertificatesServiceOp) Create(ctx context.Context, cr *CertificateRequest) (*Certificate, *Response, error) {
req, err := c.client.NewRequest(ctx, "POST", certificatesBasePath, cr)
req, err := c.client.NewRequest(ctx, http.MethodPost, certificatesBasePath, cr)
if err != nil {
return nil, nil, err
}
Expand All @@ -112,7 +113,7 @@ func (c *CertificatesServiceOp) Create(ctx context.Context, cr *CertificateReque
func (c *CertificatesServiceOp) Delete(ctx context.Context, cID string) (*Response, error) {
urlStr := path.Join(certificatesBasePath, cID)

req, err := c.client.NewRequest(ctx, "DELETE", urlStr, nil)
req, err := c.client.NewRequest(ctx, http.MethodDelete, urlStr, nil)
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions certificates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestCertificates_Get(t *testing.T) {
cID := "892071a0-bb95-49bc-8021-3afd67a210bf"
urlStr = path.Join(urlStr, cID)
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, certJSONResponse)
})

Expand All @@ -81,7 +81,7 @@ func TestCertificates_List(t *testing.T) {

urlStr := "/v2/certificates"
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, certsJSONResponse)
})

Expand Down Expand Up @@ -130,7 +130,7 @@ func TestCertificates_Create(t *testing.T) {
t.Fatal(err)
}

testMethod(t, r, "POST")
testMethod(t, r, http.MethodPost)
assert.Equal(t, createRequest, v)

fmt.Fprint(w, certJSONResponse)
Expand Down Expand Up @@ -160,7 +160,7 @@ func TestCertificates_Delete(t *testing.T) {
urlStr := "/v2/certificates"
urlStr = path.Join(urlStr, cID)
mux.HandleFunc(urlStr, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testMethod(t, r, http.MethodDelete)
})

_, err := client.Certificates.Delete(ctx, cID)
Expand Down
17 changes: 9 additions & 8 deletions domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package godo

import (
"fmt"
"net/http"

"github.com/digitalocean/godo/context"
)
Expand Down Expand Up @@ -101,7 +102,7 @@ func (s DomainsServiceOp) List(ctx context.Context, opt *ListOptions) ([]Domain,
return nil, nil, err
}

req, err := s.client.NewRequest(ctx, "GET", path, nil)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
Expand All @@ -126,7 +127,7 @@ func (s *DomainsServiceOp) Get(ctx context.Context, name string) (*Domain, *Resp

path := fmt.Sprintf("%s/%s", domainsBasePath, name)

req, err := s.client.NewRequest(ctx, "GET", path, nil)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
Expand All @@ -148,7 +149,7 @@ func (s *DomainsServiceOp) Create(ctx context.Context, createRequest *DomainCrea

path := domainsBasePath

req, err := s.client.NewRequest(ctx, "POST", path, createRequest)
req, err := s.client.NewRequest(ctx, http.MethodPost, path, createRequest)
if err != nil {
return nil, nil, err
}
Expand All @@ -169,7 +170,7 @@ func (s *DomainsServiceOp) Delete(ctx context.Context, name string) (*Response,

path := fmt.Sprintf("%s/%s", domainsBasePath, name)

req, err := s.client.NewRequest(ctx, "DELETE", path, nil)
req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -201,7 +202,7 @@ func (s *DomainsServiceOp) Records(ctx context.Context, domain string, opt *List
return nil, nil, err
}

req, err := s.client.NewRequest(ctx, "GET", path, nil)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -230,7 +231,7 @@ func (s *DomainsServiceOp) Record(ctx context.Context, domain string, id int) (*

path := fmt.Sprintf("%s/%s/records/%d", domainsBasePath, domain, id)

req, err := s.client.NewRequest(ctx, "GET", path, nil)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
Expand All @@ -256,7 +257,7 @@ func (s *DomainsServiceOp) DeleteRecord(ctx context.Context, domain string, id i

path := fmt.Sprintf("%s/%s/records/%d", domainsBasePath, domain, id)

req, err := s.client.NewRequest(ctx, "DELETE", path, nil)
req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -313,7 +314,7 @@ func (s *DomainsServiceOp) CreateRecord(ctx context.Context,
}

path := fmt.Sprintf("%s/%s/records", domainsBasePath, domain)
req, err := s.client.NewRequest(ctx, "POST", path, createRequest)
req, err := s.client.NewRequest(ctx, http.MethodPost, path, createRequest)

if err != nil {
return nil, nil, err
Expand Down
20 changes: 10 additions & 10 deletions domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestDomains_ListDomains(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/domains", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"domains": [{"name":"foo.com"},{"name":"bar.com"}]}`)
})

Expand All @@ -33,7 +33,7 @@ func TestDomains_ListDomainsMultiplePages(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/domains", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"domains": [{"id":1},{"id":2}], "links":{"pages":{"next":"http://example.com/v2/domains/?page=2"}}}`)
})

Expand Down Expand Up @@ -63,7 +63,7 @@ func TestDomains_RetrievePageByNumber(t *testing.T) {
}`

mux.HandleFunc("/v2/domains", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, jBlob)
})

Expand All @@ -81,7 +81,7 @@ func TestDomains_GetDomain(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/domains/example.com", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"domain":{"name":"example.com"}}`)
})

Expand Down Expand Up @@ -112,7 +112,7 @@ func TestDomains_Create(t *testing.T) {
t.Fatal(err)
}

testMethod(t, r, "POST")
testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, createRequest) {
t.Errorf("Request body = %+v, expected %+v", v, createRequest)
}
Expand All @@ -136,7 +136,7 @@ func TestDomains_Destroy(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/domains/example.com", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testMethod(t, r, http.MethodDelete)
})

_, err := client.Domains.Delete(ctx, "example.com")
Expand All @@ -150,7 +150,7 @@ func TestDomains_AllRecordsForDomainName(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/domains/example.com/records", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"domain_records":[{"id":1},{"id":2}]}`)
})

Expand Down Expand Up @@ -195,7 +195,7 @@ func TestDomains_GetRecordforDomainName(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/domains/example.com/records/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, `{"domain_record":{"id":1}}`)
})

Expand All @@ -215,7 +215,7 @@ func TestDomains_DeleteRecordForDomainName(t *testing.T) {
defer teardown()

mux.HandleFunc("/v2/domains/example.com/records/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testMethod(t, r, http.MethodDelete)
})

_, err := client.Domains.DeleteRecord(ctx, "example.com", 1)
Expand Down Expand Up @@ -247,7 +247,7 @@ func TestDomains_CreateRecordForDomainName(t *testing.T) {
t.Fatalf("decode json: %v", err)
}

testMethod(t, r, "POST")
testMethod(t, r, http.MethodPost)
if !reflect.DeepEqual(v, createRequest) {
t.Errorf("Request body = %+v, expected %+v", v, createRequest)
}
Expand Down
7 changes: 4 additions & 3 deletions droplet_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package godo

import (
"fmt"
"net/http"
"net/url"

"github.com/digitalocean/godo/context"
Expand Down Expand Up @@ -247,7 +248,7 @@ func (s *DropletActionsServiceOp) doAction(ctx context.Context, id int, request

path := dropletActionPath(id)

req, err := s.client.NewRequest(ctx, "POST", path, request)
req, err := s.client.NewRequest(ctx, http.MethodPost, path, request)
if err != nil {
return nil, nil, err
}
Expand All @@ -272,7 +273,7 @@ func (s *DropletActionsServiceOp) doActionByTag(ctx context.Context, tag string,

path := dropletActionPathByTag(tag)

req, err := s.client.NewRequest(ctx, "POST", path, request)
req, err := s.client.NewRequest(ctx, http.MethodPost, path, request)
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -312,7 +313,7 @@ func (s *DropletActionsServiceOp) GetByURI(ctx context.Context, rawurl string) (
}

func (s *DropletActionsServiceOp) get(ctx context.Context, path string) (*Action, *Response, error) {
req, err := s.client.NewRequest(ctx, "GET", path, nil)
req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}
Expand Down
Loading

0 comments on commit 9e24e26

Please sign in to comment.