mirror of
https://github.com/hay-kot/homebox.git
synced 2025-07-23 11:00:28 +00:00
improve documentation
This commit is contained in:
parent
c2f432cb4d
commit
e1f9c2997b
5 changed files with 83 additions and 2 deletions
|
@ -7,6 +7,19 @@ import (
|
|||
)
|
||||
|
||||
// Query is a server.Handler that decodes a query from the request and calls the provided function.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// type Query struct {
|
||||
// Foo string `schema:"foo"`
|
||||
// }
|
||||
//
|
||||
// fn := func(ctx context.Context, q Query) (any, error) {
|
||||
// // do something with q
|
||||
// return nil, nil
|
||||
// }
|
||||
//
|
||||
// r.Get("/foo", adapters.Query(fn, http.StatusOK))
|
||||
func Query[T any, Y any](f AdapterFunc[T, Y], ok int) server.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) error {
|
||||
q, err := decodeQuery[T](r)
|
||||
|
@ -24,6 +37,19 @@ func Query[T any, Y any](f AdapterFunc[T, Y], ok int) server.HandlerFunc {
|
|||
}
|
||||
|
||||
// QueryID is a server.Handler that decodes a query and an ID from the request and calls the provided function.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// type Query struct {
|
||||
// Foo string `schema:"foo"`
|
||||
// }
|
||||
//
|
||||
// fn := func(ctx context.Context, ID uuid.UUID, q Query) (any, error) {
|
||||
// // do something with ID and q
|
||||
// return nil, nil
|
||||
// }
|
||||
//
|
||||
// r.Get("/foo/{id}", adapters.QueryID(fn, http.StatusOK))
|
||||
func QueryID[T any, Y any](param string, f IDFunc[T, Y], ok int) server.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) error {
|
||||
ID, err := routeUUID(r, param)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue