Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Changed processing order and added error check #7

Merged
merged 2 commits into from
Mar 10, 2019
Merged
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
7 changes: 5 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,17 @@ func generateRequest(method string, path string, paramStruct interface{}) (*http
}

func generateRequestWithToken(method string, path string, paramStruct interface{}) (*http.Request, error) {
req, err := generateRequest(method, path, paramStruct)

token := os.Getenv("PIXELA_USER_TOKEN")
if token == "" {
return nil, fmt.Errorf("token is not set. please specify your token by PIXELA_USER_TOKEN environment variable")
}

req.Header.Set("X-USER-TOKEN", token)
req, err := generateRequest(method, path, paramStruct)

if err == nil {
req.Header.Set("X-USER-TOKEN", token)
}

return req, err
}
Expand Down