Skip to content

Commit

Permalink
add SaveDataError
Browse files Browse the repository at this point in the history
fix the curl script
  • Loading branch information
zhang-hua committed Apr 29, 2015
1 parent a3c4e04 commit 1d813de
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
9 changes: 7 additions & 2 deletions bin/curl_broker.sh
@@ -1,14 +1,19 @@
curl -X GET http://username:password@localhost:8001/v2/catalog

curl -X PUT http://username:password@localhost:8001/v2/service_instances/instance_id-111 -d "{\"service_id\":\"service-guid-111\",\"plan_id\":\"plan-guid-111\",\"organization_guid\": \"org-guid-111\",\"space_guid\":\"space-guid-111\"}"
curl -X PUT http://username:password@localhost:8001/v2/service_instances/instance_id-111 -d '{
"service_id":"service-guid-111",
"plan_id":"plan-guid-111",
"organization_guid": "org-guid-111",
"space_guid":"space-guid-111"
}' -H "Content-Type: application/json"

curl -X GET http://username:password@localhost:8001/v2/service_instances/instance_id-111

curl -X PUT http://username:password@localhost:8001/v2/service_instances/instance_id-111/service_bindings/binding_id-111 -d '{
"plan_id": "plan-guid-here",
"service_id": "service-guid-here",
"app_guid": "app-guid-here"
}' -X PUT -H "X-Broker-API-Version: 2.4" -H "Content-Type: application/json"
}' -H "Content-Type: application/json"

curl -X DELETE http://username:password@localhost:8001/v2/service_instances/instance_id-111/service_bindings/binding_id-111

Expand Down
21 changes: 21 additions & 0 deletions errors/save_data_error.go
@@ -0,0 +1,21 @@
package errors

import (
"fmt"
)

type SaveDataError struct {
Data string
Reason error
}

func NewSaveDataError(data string, reason error) *SaveDataError {
return &SaveDataError{
Data: data,
Reason: reason,
}
}

func (e *SaveDataError) Error() string {
return fmt.Sprintf("Can not save %s due to %s", e.Data, e.Reason.Error())
}
9 changes: 6 additions & 3 deletions web_server/controller.go
Expand Up @@ -92,7 +92,7 @@ func (c *Controller) CreateServiceInstance(w http.ResponseWriter, r *http.Reques

err = utils.MarshalAndRecord(c.InstanceMap, conf.DataPath, conf.ServiceInstancesFileName)
if err != nil {
fmt.Println("save to file failed: ", err)
fmt.Println(be.NewSaveDataError("ServiceInstances", err))
}

data, _ := json.Marshal(response)
Expand Down Expand Up @@ -157,6 +157,9 @@ func (c *Controller) RemoveServiceInstance(w http.ResponseWriter, r *http.Reques

delete(c.InstanceMap, serviceInstanceGuid)
utils.MarshalAndRecord(c.InstanceMap, conf.DataPath, conf.ServiceInstancesFileName)
if err != nil {
fmt.Println(be.NewSaveDataError("ServiceInstances", err))
}

w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, "{}")
Expand Down Expand Up @@ -200,7 +203,7 @@ func (c *Controller) Bind(w http.ResponseWriter, r *http.Request) {

err = utils.MarshalAndRecord(c.KeyMap, conf.DataPath, conf.ServiceKeysFileName)
if err != nil {
fmt.Println(err)
fmt.Println(be.NewSaveDataError("ServiceKeys", err))
}

fmt.Println("******", privateKey)
Expand Down Expand Up @@ -235,7 +238,7 @@ func (c *Controller) UnBind(w http.ResponseWriter, r *http.Request) {

err = utils.MarshalAndRecord(c.KeyMap, conf.DataPath, conf.ServiceKeysFileName)
if err != nil {
fmt.Println(err)
fmt.Println(be.NewSaveDataError("ServiceKeys", err))
}

w.WriteHeader(http.StatusOK)
Expand Down

0 comments on commit 1d813de

Please sign in to comment.