A Go package for building V2 Open Service Broker API compliant Service Brokers.
- Go 1.7+
- lager
- gorilla/mux
We use dep to manager our dependencies. Use dep ensure
in order to download the required packages.
brokerapi
defines a
ServiceBroker
interface. Pass an implementation of this to
brokerapi.New
, which
returns an http.Handler
that you can use to serve handle HTTP requests.
Alternatively, if you already have a *mux.Router
that you want to attach
service broker routes to, you can use
brokerapi.AttachRoutes
.
Note in this case, the Basic Authentication and Originating Identity middleware
will not be set up, so you will have to attach them manually if required.
brokerapi
defines a handful of error types in service_broker.go
for some common error cases that your service broker may encounter. Return these from your ServiceBroker
methods where appropriate, and brokerapi
will do the "right thing" (โข), and give Cloud Foundry an appropriate status code, as per the Service Broker API specification.
NewFailureResponse()
allows you to return a custom error from any of the ServiceBroker
interface methods which return an error. Within this you must define an error, a HTTP response status code and a logging key. You can also use the NewFailureResponseBuilder()
to add a custom Error:
value in the response, or indicate that the broker should return an empty response rather than the error message.
You can see the cf-redis service broker uses the BrokerAPI package to create a service broker for Redis.