| 1 | // Package jsonclient provides a JSON HTTP client for making HTTP requests |
| 2 | // that automatically marshal and unmarshal JSON payloads. |
| 3 | package jsonclientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ |
| 4 | |
| 5 | import ( |
| 6 | "bytesscip-go gomod github.com/golang/go/src . bytes/" |
| 7 | "contextscip-go gomod github.com/golang/go/src . context/" |
| 8 | "encoding/jsonscip-go gomod github.com/golang/go/src . `encoding/json`/" |
| 9 | "errorsscip-go gomod github.com/golang/go/src . errors/" |
| 10 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 11 | "ioscip-go gomod github.com/golang/go/src . io/" |
| 12 | "net/httpscip-go gomod github.com/golang/go/src . `net/http`/" |
| 13 | |
| 14 | "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 15 | ) |
| 16 | |
| 17 | // Client defines the interface for JSON HTTP operations. |
| 18 | type Clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client# interface { |
| 19 | Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Get.(url string, response any) error |
| 20 | Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.(url string, request, response any) error |
| 21 | Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Headers.() httpscip-go gomod github.com/golang/go/src . `net/http`/.Headerscip-go gomod github.com/golang/go/src . `net/http`/Header# |
| 22 | ErrorResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#ErrorResponse.(err error, response any) bool |
| 23 | } |
| 24 | |
| 25 | // Error contains additional HTTP/JSON details. |
| 26 | type Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# struct { |
| 27 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode. int |
| 28 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body. string |
| 29 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err. error |
| 30 | } |
| 31 | |
| 32 | // client wraps an HTTP client for JSON operations. |
| 33 | type clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client# struct { |
| 34 | httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#httpClient. typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient# |
| 35 | headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#headers. httpscip-go gomod github.com/golang/go/src . `net/http`/.Headerscip-go gomod github.com/golang/go/src . `net/http`/Header# |
| 36 | indentscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#indent. string |
| 37 | } |
| 38 | |
| 39 | // ContentType defines the default MIME type for JSON requests. |
| 40 | const ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType. = "application/json" |
| 41 | |
| 42 | // HTTPClientErrorThreshold specifies the status code threshold for client errors (400+). |
| 43 | const HTTPClientErrorThresholdscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/HTTPClientErrorThreshold. = 400 |
| 44 | |
| 45 | // ErrUnexpectedStatus indicates an unexpected HTTP response status. |
| 46 | var ErrUnexpectedStatusscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ErrUnexpectedStatus. = errorsscip-go gomod github.com/golang/go/src . errors/.Newscip-go gomod github.com/golang/go/src . errors/New().("got unexpected HTTP status") |
| 47 | |
| 48 | // DefaultClient provides a singleton JSON client using http.DefaultClient. |
| 49 | // |
| 50 | // Deprecated: Use NewWithHTTPClient with an explicit client instead. |
| 51 | // This will continue to use http.DefaultClient. |
| 52 | var DefaultClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/DefaultClient. = NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() |
| 53 | |
| 54 | // Error returns the string representation of the error. |
| 55 | func (je Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#) Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Error().() string { |
| 56 | return je.Stringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#String().() |
| 57 | } |
| 58 | |
| 59 | // String provides a human-readable description of the error. |
| 60 | func (je Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#) Stringscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#String().() string { |
| 61 | if je.errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err. == nil { |
| 62 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Sprintfscip-go gomod github.com/golang/go/src . fmt/Sprintf().("unknown error (HTTP %v)", je.StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.) |
| 63 | } |
| 64 | |
| 65 | return je.errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err..Error() |
| 66 | } |
| 67 | |
| 68 | // ErrorBody extracts the request body from an error if it's a jsonclient.Error. |
| 69 | func ErrorBodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ErrorBody().(e error) string { |
| 70 | var jsonError Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 71 | if errorsscip-go gomod github.com/golang/go/src . errors/.Asscip-go gomod github.com/golang/go/src . errors/As().(e, &jsonError) { |
| 72 | return jsonError.Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body. |
| 73 | } |
| 74 | |
| 75 | return "" |
| 76 | } |
| 77 | |
| 78 | // NewClient creates a new JSON client using the default http.Client. |
| 79 | // |
| 80 | // Deprecated: Use NewWithHTTPClient with an explicit client instead. |
| 81 | func NewClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewClient().() Clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client# { |
| 82 | return NewWithHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewWithHTTPClient().(httpscip-go gomod github.com/golang/go/src . `net/http`/.DefaultClientscip-go gomod github.com/golang/go/src . `net/http`/DefaultClient.) |
| 83 | } |
| 84 | |
| 85 | // NewWithHTTPClient creates a new JSON client using the specified HTTP client. |
| 86 | func NewWithHTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/NewWithHTTPClient().(httpClient typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.HTTPClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient#) Clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client# { |
| 87 | return &clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#{ |
| 88 | httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#httpClient.: httpClient, |
| 89 | headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#headers.: httpscip-go gomod github.com/golang/go/src . `net/http`/.Headerscip-go gomod github.com/golang/go/src . `net/http`/Header#{ |
| 90 | "Content-Type": []string{ContentTypescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ContentType.}, |
| 91 | }, |
| 92 | indentscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#indent.: "", |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | // Get fetches a URL using GET and unmarshals the response into the provided object using DefaultClient. |
| 97 | // |
| 98 | // Deprecated: Create a Client with NewWithHTTPClient and call Get on it instead. |
| 99 | func Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Get().(url string, response any) error { |
| 100 | if err := DefaultClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/DefaultClient..Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Get.(url, response); err != nil { |
| 101 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("getting JSON from %q: %w", url, err) |
| 102 | } |
| 103 | |
| 104 | return nil |
| 105 | } |
| 106 | |
| 107 | // Post sends a request as JSON and unmarshals the response into the provided object using DefaultClient. |
| 108 | // |
| 109 | // Deprecated: Create a Client with NewWithHTTPClient and call Post on it instead. |
| 110 | func Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Post().(url string, request, response any) error { |
| 111 | if err := DefaultClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/DefaultClient..Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Client#Post.(url, request, response); err != nil { |
| 112 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("posting JSON to %q: %w", url, err) |
| 113 | } |
| 114 | |
| 115 | return nil |
| 116 | } |
| 117 | |
| 118 | // ErrorResponse checks if an error is a JSON error and unmarshals its body into the response. |
| 119 | func (c *clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#) ErrorResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#ErrorResponse().(err error, response any) bool { |
| 120 | var errMsg Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error# |
| 121 | if errorsscip-go gomod github.com/golang/go/src . errors/.Asscip-go gomod github.com/golang/go/src . errors/As().(err, &errMsg) { |
| 122 | return jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src . `encoding/json`/Unmarshal().([]byte(errMsg.Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.), response) == nil |
| 123 | } |
| 124 | |
| 125 | return false |
| 126 | } |
| 127 | |
| 128 | // Get fetches a URL using GET and unmarshals the response into the provided object. |
| 129 | func (c *clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#) Getscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#Get().(url string, response any) error { |
| 130 | req, err := httpscip-go gomod github.com/golang/go/src . `net/http`/.NewRequestWithContextscip-go gomod github.com/golang/go/src . `net/http`/NewRequestWithContext().(contextscip-go gomod github.com/golang/go/src . context/.Backgroundscip-go gomod github.com/golang/go/src . context/Background().(), httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodGetscip-go gomod github.com/golang/go/src . `net/http`/MethodGet., url, httpscip-go gomod github.com/golang/go/src . `net/http`/.NoBodyscip-go gomod github.com/golang/go/src . `net/http`/NoBody.) |
| 131 | if err != nil { |
| 132 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("creating GET request for %q: %w", url, err) |
| 133 | } |
| 134 | |
| 135 | for key, val := range c.headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#headers. { |
| 136 | req.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().(key, val[0]) |
| 137 | } |
| 138 | |
| 139 | res, err := c.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#httpClient..Doscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient#Do.(req) |
| 140 | if err != nil { |
| 141 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("executing GET request to %q: %w", url, err) |
| 142 | } |
| 143 | |
| 144 | defer func() { _ = res.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 145 | |
| 146 | return parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/parseResponse().(res, response) |
| 147 | } |
| 148 | |
| 149 | // Headers returns the default headers for requests. |
| 150 | func (c *clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#) Headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#Headers().() httpscip-go gomod github.com/golang/go/src . `net/http`/.Headerscip-go gomod github.com/golang/go/src . `net/http`/Header# { |
| 151 | return c.headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#headers. |
| 152 | } |
| 153 | |
| 154 | // Post sends a request as JSON and unmarshals the response into the provided object. |
| 155 | func (c *clientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#) Postscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#Post().(url string, request, response any) error { |
| 156 | var err error |
| 157 | |
| 158 | var body []byte |
| 159 | |
| 160 | if strReq, ok := request.(string); ok { |
| 161 | // If the request is a string, pass it through without serializing |
| 162 | body = []byte(strReq) |
| 163 | } else { |
| 164 | body, err = jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.MarshalIndentscip-go gomod github.com/golang/go/src . `encoding/json`/MarshalIndent().(request, "", c.indentscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#indent.) |
| 165 | if err != nil { |
| 166 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("marshaling request to JSON: %w", err) |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | req, err := httpscip-go gomod github.com/golang/go/src . `net/http`/.NewRequestWithContextscip-go gomod github.com/golang/go/src . `net/http`/NewRequestWithContext().( |
| 171 | contextscip-go gomod github.com/golang/go/src . context/.Backgroundscip-go gomod github.com/golang/go/src . context/Background().(), |
| 172 | httpscip-go gomod github.com/golang/go/src . `net/http`/.MethodPostscip-go gomod github.com/golang/go/src . `net/http`/MethodPost., |
| 173 | url, |
| 174 | bytesscip-go gomod github.com/golang/go/src . bytes/.NewReaderscip-go gomod github.com/golang/go/src . bytes/NewReader().(body), |
| 175 | ) |
| 176 | if err != nil { |
| 177 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("creating POST request for %q: %w", url, err) |
| 178 | } |
| 179 | |
| 180 | for key, val := range c.headersscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#headers. { |
| 181 | req.Headerscip-go gomod github.com/golang/go/src . `net/http`/Request#Header..Setscip-go gomod github.com/golang/go/src . `net/http`/Header#Set().(key, val[0]) |
| 182 | } |
| 183 | |
| 184 | res, err := c.httpClientscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/client#httpClient..Doscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/HTTPClient#Do.(req) |
| 185 | if err != nil { |
| 186 | return fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("sending POST request to %q: %w", url, err) |
| 187 | } |
| 188 | |
| 189 | defer func() { _ = res.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body..Closescip-go gomod github.com/golang/go/src . io/Closer#Close().() }() |
| 190 | |
| 191 | return parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/parseResponse().(res, response) |
| 192 | } |
| 193 | |
| 194 | // parseResponse parses the HTTP response and unmarshals it into the provided object. |
| 195 | func parseResponsescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/parseResponse().(res *httpscip-go gomod github.com/golang/go/src . `net/http`/.Responsescip-go gomod github.com/golang/go/src . `net/http`/Response#, response any) error { |
| 196 | body, err := ioscip-go gomod github.com/golang/go/src . io/.ReadAllscip-go gomod github.com/golang/go/src . io/ReadAll().(res.Bodyscip-go gomod github.com/golang/go/src . `net/http`/Response#Body.) |
| 197 | |
| 198 | if res.StatusCodescip-go gomod github.com/golang/go/src . `net/http`/Response#StatusCode. >= HTTPClientErrorThresholdscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/HTTPClientErrorThreshold. { |
| 199 | err = fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("%w: %v", ErrUnexpectedStatusscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/ErrUnexpectedStatus., res.Statusscip-go gomod github.com/golang/go/src . `net/http`/Response#Status.) |
| 200 | } |
| 201 | |
| 202 | if err == nil { |
| 203 | err = jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.Unmarshalscip-go gomod github.com/golang/go/src . `encoding/json`/Unmarshal().(body, response) |
| 204 | } |
| 205 | |
| 206 | if err != nil { |
| 207 | if body == nil { |
| 208 | body = []byte{} |
| 209 | } |
| 210 | |
| 211 | return Errorscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#{ |
| 212 | StatusCodescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#StatusCode.: res.StatusCodescip-go gomod github.com/golang/go/src . `net/http`/Response#StatusCode., |
| 213 | Bodyscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#Body.: string(body), |
| 214 | errscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/util/jsonclient`/Error#err.: err, |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | return nil |
| 219 | } |