* GetPumpHandler handles request/response marshaling and validation for Get /gas-stations/{gasStationId}/pumps/{pumpId} */
(service GetPumpHandlerService)
| 254 | Get /gas-stations/{gasStationId}/pumps/{pumpId} |
| 255 | */ |
| 256 | func GetPumpHandler(service GetPumpHandlerService) http.Handler { |
| 257 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 258 | defer errors.HandleRequest("GetPumpHandler", w, r) |
| 259 | |
| 260 | // Trace the service function handler execution |
| 261 | span := sentry.StartSpan(r.Context(), "http.server", sentry.WithDescription("GetPumpHandler")) |
| 262 | defer span.Finish() |
| 263 | |
| 264 | ctx := span.Context() |
| 265 | r = r.WithContext(ctx) |
| 266 | |
| 267 | // Setup context, response writer and request type |
| 268 | writer := getPumpResponseWriter{ |
| 269 | ResponseWriter: metrics.NewMetric("fueling", "/gas-stations/{gasStationId}/pumps/{pumpId}", w, r), |
| 270 | } |
| 271 | request := GetPumpRequest{ |
| 272 | Request: r, |
| 273 | } |
| 274 | |
| 275 | // Scan and validate incoming request parameters |
| 276 | vars := mux.Vars(r) |
| 277 | if !runtime.ScanParameters(w, r, &runtime.ScanParameter{ |
| 278 | Data: &request.ParamGasStationID, |
| 279 | Location: runtime.ScanInPath, |
| 280 | Input: vars["gasStationId"], |
| 281 | Name: "gasStationId", |
| 282 | }, &runtime.ScanParameter{ |
| 283 | Data: &request.ParamPumpID, |
| 284 | Location: runtime.ScanInPath, |
| 285 | Input: vars["pumpId"], |
| 286 | Name: "pumpId", |
| 287 | }) { |
| 288 | return |
| 289 | } |
| 290 | if !runtime.ValidateParameters(w, r, &request) { |
| 291 | return // invalid request stop further processing |
| 292 | } |
| 293 | |
| 294 | // Invoke service that implements the business logic |
| 295 | err := service.GetPump(ctx, &writer, &request) |
| 296 | select { |
| 297 | case <-ctx.Done(): |
| 298 | if ctx.Err() != nil { |
| 299 | // Context cancellation should not be reported if it's the request context |
| 300 | w.WriteHeader(499) |
| 301 | if err != nil && !(errors1.Is(err, context.Canceled) || errors1.Is(err, context.DeadlineExceeded)) { |
| 302 | // Report unclean error handling (err != context err) to sentry |
| 303 | errors.Handle(ctx, err) |
| 304 | } |
| 305 | } |
| 306 | default: |
| 307 | if err != nil { |
| 308 | errors.HandleError(err, "GetPumpHandler", w, r) |
| 309 | } |
| 310 | } |
| 311 | }) |
| 312 | } |
| 313 |
no test coverage detected
searching dependent graphs…