github.com/companieshouse/lfp-pay-api@v0.0.0-20230203133422-0ca455cd79f9/handlers/payable_resource.go (about) 1 package handlers 2 3 import ( 4 "fmt" 5 "net/http" 6 7 "github.com/companieshouse/chs.go/log" 8 "github.com/companieshouse/lfp-pay-api-core/models" 9 "github.com/companieshouse/lfp-pay-api/config" 10 "github.com/companieshouse/lfp-pay-api/utils" 11 ) 12 13 // HandleGetPayableResource retrieves the payable resource from request context 14 func HandleGetPayableResource(w http.ResponseWriter, req *http.Request) { 15 16 // get payable resource from context, put there by PayableResourceAuthenticationInterceptor 17 payableResource, ok := req.Context().Value(config.PayableResource).(*models.PayableResource) 18 19 if !ok { 20 log.ErrorR(req, fmt.Errorf("invalid PayableResource in request context")) 21 m := models.NewMessageResponse("the payable resource is not present in the request context") 22 utils.WriteJSONWithStatus(w, req, m, http.StatusInternalServerError) 23 return 24 } 25 26 utils.WriteJSON(w, req, payableResource) 27 }