forked from mirrors/homebox
Initial commit
This commit is contained in:
commit
29f583e936
135 changed files with 18463 additions and 0 deletions
30
backend/internal/mocks/chimocker/chimocker.go
Normal file
30
backend/internal/mocks/chimocker/chimocker.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package chimocker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
)
|
||||
|
||||
type Params map[string]string
|
||||
|
||||
// WithUrlParam returns a pointer to a request object with the given URL params
|
||||
// added to a new chi.Context object.
|
||||
func WithUrlParam(r *http.Request, key, value string) *http.Request {
|
||||
chiCtx := chi.NewRouteContext()
|
||||
req := r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, chiCtx))
|
||||
chiCtx.URLParams.Add(key, value)
|
||||
return req
|
||||
}
|
||||
|
||||
// WithUrlParams returns a pointer to a request object with the given URL params
|
||||
// added to a new chi.Context object. for single param assignment see WithUrlParam
|
||||
func WithUrlParams(r *http.Request, params Params) *http.Request {
|
||||
chiCtx := chi.NewRouteContext()
|
||||
req := r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, chiCtx))
|
||||
for key, value := range params {
|
||||
chiCtx.URLParams.Add(key, value)
|
||||
}
|
||||
return req
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue