(pattern EndpointPattern, response any)
| 700 | } |
| 701 | |
| 702 | func WithRequestMatch(pattern EndpointPattern, response any) MockBackendOption { |
| 703 | return func(handlers map[string]http.HandlerFunc) { |
| 704 | method, path := parseEndpointPattern(pattern) |
| 705 | handlers[method+" "+path] = func(w http.ResponseWriter, _ *http.Request) { |
| 706 | w.WriteHeader(http.StatusOK) |
| 707 | switch v := response.(type) { |
| 708 | case string: |
| 709 | _, _ = w.Write([]byte(v)) |
| 710 | case []byte: |
| 711 | _, _ = w.Write(v) |
| 712 | default: |
| 713 | data, err := json.Marshal(v) |
| 714 | if err == nil { |
| 715 | _, _ = w.Write(data) |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | } |
| 720 | } |
| 721 | |
| 722 | func WithRequestMatchHandler(pattern EndpointPattern, handler http.HandlerFunc) MockBackendOption { |
| 723 | return func(handlers map[string]http.HandlerFunc) { |
no test coverage detected