Skip to content

Commit

Permalink
Merge pull request #211 from xperimental/prepend-slash
Browse files Browse the repository at this point in the history
Prepend slash to service ID in DELETE
  • Loading branch information
j1n6 authored Jun 22, 2016
2 parents 7539277 + 21d8f39 commit e08654b
Showing 1 changed file with 16 additions and 2 deletions.
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

0 comments on commit e08654b

Please sign in to comment.