Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix function comments based on best practices from Effective Go #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type ApiStruct struct {
PathSuffix string
}

// Create a new API Instance and returns a Resource
// Api: Create a new API Instance and returns a Resource
// Accepts URL as parameter, and either a Basic Auth or a OAuth2 Client.
func Api(baseUrl string, options ...interface{}) *Resource {
u, err := url.Parse(baseUrl)
Expand Down
26 changes: 13 additions & 13 deletions resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type Resource struct {
Raw *http.Response
}

// Creates a new Resource.
// Res: Creates a new Resource.
func (r *Resource) Res(options ...interface{}) *Resource {
if len(options) > 0 {
var url string
Expand All @@ -64,7 +64,7 @@ func (r *Resource) Res(options ...interface{}) *Resource {
return r
}

// Same as Res() Method, but returns a Resource with url resource/:id
// Id: Same as Res() Method, but returns a Resource with url resource/:id
func (r *Resource) Id(options ...interface{}) *Resource {
if len(options) > 0 {
id := ""
Expand All @@ -91,7 +91,7 @@ func (r *Resource) Id(options ...interface{}) *Resource {
return r
}

// Sets QueryValues for current Resource
// SetQuery: Sets QueryValues for current Resource
func (r *Resource) SetQuery(querystring map[string]string) *Resource {
r.QueryValues = make(url.Values)
for k, v := range querystring {
Expand All @@ -100,7 +100,7 @@ func (r *Resource) SetQuery(querystring map[string]string) *Resource {
return r
}

// Performs a GET request on given Resource
// Get: Performs a GET request on given Resource
// Accepts map[string]string as parameter, will be used as querystring.
func (r *Resource) Get(options ...interface{}) (*Resource, error) {
if len(options) > 0 {
Expand All @@ -114,7 +114,7 @@ func (r *Resource) Get(options ...interface{}) (*Resource, error) {
return r.do("GET")
}

// Performs a HEAD request on given Resource
// Head: Performs a HEAD request on given Resource
// Accepts map[string]string as parameter, will be used as querystring.
func (r *Resource) Head(options ...interface{}) (*Resource, error) {
if len(options) > 0 {
Expand All @@ -127,7 +127,7 @@ func (r *Resource) Head(options ...interface{}) (*Resource, error) {
return r.do("HEAD")
}

// Performs a PUT request on given Resource.
// Put: Performs a PUT request on given Resource.
// Accepts interface{} as parameter, will be used as payload.
func (r *Resource) Put(options ...interface{}) (*Resource, error) {
if len(options) > 0 {
Expand All @@ -136,7 +136,7 @@ func (r *Resource) Put(options ...interface{}) (*Resource, error) {
return r.do("PUT")
}

// Performs a POST request on given Resource.
// Post: Performs a POST request on given Resource.
// Accepts interface{} as parameter, will be used as payload.
func (r *Resource) Post(options ...interface{}) (*Resource, error) {
if len(options) > 0 {
Expand All @@ -145,7 +145,7 @@ func (r *Resource) Post(options ...interface{}) (*Resource, error) {
return r.do("POST")
}

// Performs a Delete request on given Resource.
// Delete: Performs a Delete request on given Resource.
// Accepts map[string]string as parameter, will be used as querystring.
func (r *Resource) Delete(options ...interface{}) (*Resource, error) {
if len(options) > 0 {
Expand All @@ -158,7 +158,7 @@ func (r *Resource) Delete(options ...interface{}) (*Resource, error) {
return r.do("DELETE")
}

// Performs a Delete request on given Resource.
// Options: Performs a Delete request on given Resource.
// Accepts map[string]string as parameter, will be used as querystring.
func (r *Resource) Options(options ...interface{}) (*Resource, error) {
if len(options) > 0 {
Expand All @@ -171,7 +171,7 @@ func (r *Resource) Options(options ...interface{}) (*Resource, error) {
return r.do("OPTIONS")
}

// Performs a PATCH request on given Resource.
// Patch: Performs a PATCH request on given Resource.
// Accepts interface{} as parameter, will be used as payload.
func (r *Resource) Patch(options ...interface{}) (*Resource, error) {
if len(options) > 0 {
Expand Down Expand Up @@ -234,20 +234,20 @@ func (r *Resource) do(method string) (*Resource, error) {
return r, nil
}

// Sets Payload for current Resource
// SetPayload: Sets Payload for current Resource
func (r *Resource) SetPayload(args interface{}) io.Reader {
var b []byte
b, _ = json.Marshal(args)
r.SetHeader("Content-Type", "application/json")
return bytes.NewBuffer(b)
}

// Sets Headers
// SetHeader: Sets Headers
func (r *Resource) SetHeader(key string, value string) {
r.Headers.Add(key, value)
}

// Overwrites the client that will be used for requests.
// SetClient: Overwrites the client that will be used for requests.
// For example if you want to use your own client with OAuth2
func (r *Resource) SetClient(c *http.Client) {
r.Api.Client = c
Expand Down