Skip to content

Commit

Permalink
Fixed some issues found by Codacy
Browse files Browse the repository at this point in the history
Still don't fully understand the rules of Markdown indentation... Hope, this is correct
  • Loading branch information
kolayne committed Jan 18, 2021
1 parent c2aaaa0 commit a8db7c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
26 changes: 15 additions & 11 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,21 @@ All the API methods (except `/login`):
human-readable explanation of the error occurred while processing your request)

- Returns a relevant HTTP status code. Common status codes for all methods are:
- `200 OK` for requests handled without errors
- `400 Bad Request` for requests with either an incorrect set of parameters or syntactically incorrect parameters'
values (if, however, the values are syntactically correct, but are not logically correct, don't satisfy some
invariants, etc, you should get a different error code, most likely `412 Precondition Failed` or something even
more specific).

**WARNING**: you are not guarantied to get such response if you send a request with parameters not documented for
an API method. It is possible that extra parameters will just be ignored
- `401 Unauthorized` for requests sent without (or with incorrect/expired) cookies
- `405 Method Not Allowed` for requests with incorrect HTTP Method
- `500 Internal Server Error` for requests, which failed due to a server-side error
- `200 OK` for requests handled without errors

- `400 Bad Request` for requests with either an incorrect set of parameters or syntactically incorrect parameters'
values (if, however, the values are syntactically correct, but are not logically correct, don't satisfy some
invariants, etc, you should get a different error code, most likely `412 Precondition Failed` or something even more
specific).

**WARNING**: you are not guarantied to get such response if you send a request with parameters not documented for an
API method. It is possible that extra parameters will just be ignored

- `401 Unauthorized` for requests sent without (or with incorrect/expired) cookies

- `405 Method Not Allowed` for requests with incorrect HTTP Method

- `500 Internal Server Error` for requests, which failed due to a server-side error

Please, note, that if there were multiple problems while processing your request and there are multiple status codes
applicable for your case, you can get a response with any of them (for example, if you send a bad request, and you are
Expand Down
4 changes: 2 additions & 2 deletions src/webhandlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func HandleApiDays(w http.ResponseWriter, r *http.Request) {
panicIfError(err)
}

func HandleApiDaysBrief(w http.ResponseWriter, r *http.Request) {
func HandleAPIDaysBrief(w http.ResponseWriter, r *http.Request) {
session, _ := cookieStorage.Get(r, "session")
if session.IsNew {
http.Error(w, "You should be authorized to call this method", http.StatusUnauthorized)
Expand Down Expand Up @@ -209,7 +209,7 @@ func main() {
w.Write([]byte("Hi..."))
})
api.HandleFunc("/api/days", HandleApiDays).Methods("POST")
api.HandleFunc("/api/days/brief", HandleApiDaysBrief).Methods("GET")
api.HandleFunc("/api/days/brief", HandleAPIDaysBrief).Methods("GET")
//api.HandleFunc("/api/days/{id:[0-9]+}")

final := http.NewServeMux()
Expand Down

0 comments on commit a8db7c5

Please sign in to comment.