MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / add

Method add

server/router.go:170–204  ·  view source on GitHub ↗

add adds an abitary route to the router

(method, path string, handler RouteHandler, middlewares ...Middleware)

Source from the content-addressed store, hash-verified

168
169// add adds an abitary route to the router
170func (r *Router) add(method, path string, handler RouteHandler, middlewares ...Middleware) *route {
171 for _, m := range middlewares {
172 handler = m(handler)
173 }
174
175 exact := true
176 if strings.HasSuffix(path, "*") {
177 exact = false
178 path = strings.TrimSuffix(path, "*")
179 }
180
181 newRoute := &route{
182 method: method,
183 path: r.config.PathPrefix + path,
184 handler: handler,
185 exact: exact,
186 }
187
188 r.routes = append(r.routes, newRoute)
189
190 // Sort routes by exact flag, exact routes go first in the
191 // same order they were added
192 slices.SortStableFunc(r.routes, func(a, b *route) int {
193 switch {
194 case a.exact == b.exact:
195 return 0
196 case a.exact:
197 return -1
198 default:
199 return 1
200 }
201 })
202
203 return newRoute
204}
205
206// getRequestID tries to read request id from headers or from lambda
207// context or generates a new one if nothing found.

Callers 4

GETMethod · 0.95
OPTIONSMethod · 0.95
HEADMethod · 0.95
index.jsFile · 0.80

Calls 1

HasSuffixMethod · 0.80

Tested by

no test coverage detected