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

Prepend slash to service ID in DELETE #211

Merged
merged 2 commits into from
Jun 22, 2016
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
18 changes: 16 additions & 2 deletions api/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,17 @@ func (d *ServiceAPI) Put(params martini.Params, w http.ResponseWriter, r *http.R
}

func (d *ServiceAPI) Delete(params martini.Params, w http.ResponseWriter, r *http.Request) {
serviceId := params["_1"]
err := d.Storage.Delete(serviceId)
serviceID := params["_1"]
if len(serviceID) == 0 {
responseError(w, "can not use empty ID")
return
}

if !strings.HasPrefix(serviceID, "/") {
serviceID = "/" + serviceID
}

err := d.Storage.Delete(serviceID)
if err != nil {
responseError(w, err.Error())
return
Expand All @@ -85,6 +94,11 @@ func extractService(r *http.Request) (service.Service, error) {
if err != nil {
return serviceModel, errors.New("Unable to decode JSON request")
}

if len(serviceModel.Id) == 0 {
return serviceModel, errors.New("can not use empty ID")
}

if !strings.HasPrefix(serviceModel.Id, "/") {
serviceModel.Id = "/" + serviceModel.Id
}
Expand Down