November 2018
Intermediate to advanced
346 pages
8h 12m
English
Finally, now for the key changes. First, we extract the context from the request:
// ServeHTTP implements http.Handlerfunc (h *RegisterHandler) ServeHTTP(response http.ResponseWriter, request *http.Request) { // extract payload from request requestPayload, err := h.extractPayload(request) if err != nil { // output error response.WriteHeader(http.StatusBadRequest) return } // call the business logic using the request data and context id, err := h.register(request.Context(), requestPayload) if err != nil { // not need to log here as we can expect other layers to do so response.WriteHeader(http.StatusBadRequest) return } // happy path response.Header().Add("Location", fmt.Sprintf
Read now
Unlock full access