ducky/subscriptions

Paddy 2015-10-04 Parent:0ae1ff0ee306

16:b063bc0a6e84 Go to Latest

ducky/subscriptions/api/subscription_handlers.go

Make api subpackage golint-passing. Add comments to all the exported functions, methods, and variables in the api subpackage, to make golint happy. Also, make the individual endpoints in the api subpackage unexported, as there's no real use case for exporting them. The handlers depend on the placeholders in the endpoint, so we need them to be controlled in unison, which means it's probably a bad idea to declare the route outside of the API package. And the only reason to expose the Handler is so people can declare custom endpoints.

History
     1.1 --- a/api/subscription_handlers.go	Wed Sep 30 01:33:53 2015 -0700
     1.2 +++ b/api/subscription_handlers.go	Sun Oct 04 21:58:07 2015 -0700
     1.3 @@ -14,7 +14,16 @@
     1.4  )
     1.5  
     1.6  var (
     1.7 -	ScopeSubscription      = auth.Scope{ID: "subscriptions", Name: "Manage Subscriptions", Description: "Read and update your subscription information."}
     1.8 +	// ScopeSubscription is an auth.Scope that controls access to
     1.9 +	// subscriptions.
    1.10 +	ScopeSubscription = auth.Scope{
    1.11 +		ID:          "subscriptions",
    1.12 +		Name:        "Manage Subscriptions",
    1.13 +		Description: "Read and update your subscription information.",
    1.14 +	}
    1.15 +	// ScopeSubscriptionAdmin is an auth.Scope that controls access
    1.16 +	// to subscriptions, bypassing the ACL to achieve administrator
    1.17 +	// access.
    1.18  	ScopeSubscriptionAdmin = auth.Scope{ID: "subscriptions_admin", Name: "Administer Subscriptions", Description: "Read and update subscription information, bypassing ACL."}
    1.19  )
    1.20  
    1.21 @@ -57,16 +66,19 @@
    1.22  	return changes
    1.23  }
    1.24  
    1.25 +// HandleSubscriptions registers the endpoints for the subscriptions API
    1.26 +// with the passed router. the passed Context will be passed to all the
    1.27 +// http.Handlers for the endpoints.
    1.28  func HandleSubscriptions(router *trout.Router, c context.Context) {
    1.29  	router.Endpoint("/subscriptions").Methods("POST", "OPTIONS").Handler(
    1.30 -		api.CORSMiddleware(api.NegotiateMiddleware(api.ContextWrapper(c, CreateSubscriptionHandler))))
    1.31 +		api.CORSMiddleware(api.NegotiateMiddleware(api.ContextWrapper(c, createSubscriptionHandler))))
    1.32  	router.Endpoint("/subscriptions/{id}").Methods("GET", "OPTIONS").Handler(
    1.33 -		api.CORSMiddleware(api.NegotiateMiddleware(api.ContextWrapper(c, GetSubscriptionHandler))))
    1.34 +		api.CORSMiddleware(api.NegotiateMiddleware(api.ContextWrapper(c, getSubscriptionHandler))))
    1.35  	router.Endpoint("/subscriptions/{id}").Methods("PATCH", "OPTIONS").Handler(
    1.36 -		api.CORSMiddleware(api.NegotiateMiddleware(api.ContextWrapper(c, PatchSubscriptionHandler))))
    1.37 +		api.CORSMiddleware(api.NegotiateMiddleware(api.ContextWrapper(c, patchSubscriptionHandler))))
    1.38  }
    1.39  
    1.40 -func CreateSubscriptionHandler(w http.ResponseWriter, r *http.Request, c context.Context) {
    1.41 +func createSubscriptionHandler(w http.ResponseWriter, r *http.Request, c context.Context) {
    1.42  	store, err := getSubscriptionStore(c)
    1.43  	if err != nil {
    1.44  		api.Encode(w, r, http.StatusInternalServerError, Response{Errors: api.ActOfGodError})
    1.45 @@ -110,7 +122,7 @@
    1.46  	api.Encode(w, r, http.StatusCreated, resp)
    1.47  }
    1.48  
    1.49 -func GetSubscriptionHandler(w http.ResponseWriter, r *http.Request, c context.Context) {
    1.50 +func getSubscriptionHandler(w http.ResponseWriter, r *http.Request, c context.Context) {
    1.51  	store, err := getSubscriptionStore(c)
    1.52  	if err != nil {
    1.53  		api.Encode(w, r, http.StatusInternalServerError, Response{Errors: api.ActOfGodError})
    1.54 @@ -154,7 +166,7 @@
    1.55  	api.Encode(w, r, http.StatusOK, resp)
    1.56  }
    1.57  
    1.58 -func PatchSubscriptionHandler(w http.ResponseWriter, r *http.Request, c context.Context) {
    1.59 +func patchSubscriptionHandler(w http.ResponseWriter, r *http.Request, c context.Context) {
    1.60  	store, err := getSubscriptionStore(c)
    1.61  	if err != nil {
    1.62  		api.Encode(w, r, http.StatusInternalServerError, Response{Errors: api.ActOfGodError})