Skip to content

Commit

Permalink
Allow usage of POST for /leave
Browse files Browse the repository at this point in the history
Adding a deprecation warning message.

Use http package constants for http verbs
  • Loading branch information
Victor Castell committed Dec 10, 2016
1 parent 7a5526a commit bffd1b4
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions dkron/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ func (a *AgentCommand) apiRoutes(r *mux.Router) {
subver.HandleFunc("/", a.indexHandler)
subver.HandleFunc("/members", a.membersHandler)
subver.HandleFunc("/leader", a.leaderHandler)
subver.HandleFunc("/leave", a.leaveHandler)
subver.HandleFunc("/leave", a.leaveHandler).Methods(http.MethodGet, http.MethodPost)

subver.Path("/jobs").HandlerFunc(a.jobCreateOrUpdateHandler).Methods("POST", "PATCH")
subver.Path("/jobs").HandlerFunc(a.jobCreateOrUpdateHandler).Methods(http.MethodPost, http.MethodPatch)
// Place fallback routes last
subver.Path("/jobs").HandlerFunc(a.jobsHandler)

sub := subver.PathPrefix("/jobs").Subrouter()
sub.HandleFunc("/{job}", a.jobDeleteHandler).Methods("DELETE")
sub.HandleFunc("/{job}", a.jobRunHandler).Methods("POST")
sub.HandleFunc("/{job}", a.jobDeleteHandler).Methods(http.MethodDelete)
sub.HandleFunc("/{job}", a.jobRunHandler).Methods(http.MethodPost)
// Place fallback routes last
sub.HandleFunc("/{job}", a.jobGetHandler)

Expand Down Expand Up @@ -300,6 +300,9 @@ func (a *AgentCommand) leaderHandler(w http.ResponseWriter, r *http.Request) {
}

func (a *AgentCommand) leaveHandler(w http.ResponseWriter, r *http.Request) {
if r.Method == http.MethodGet {
log.Warn("/leave GET is deprecated and will be removed, use POST")
}
if err := a.serf.Leave(); err != nil {
if err := printJson(w, r, a.listServers()); err != nil {
log.Fatal(err)
Expand Down

0 comments on commit bffd1b4

Please sign in to comment.