improve documentation

This commit is contained in:
Hayden 2023-03-05 20:17:53 -09:00
parent c2f432cb4d
commit e1f9c2997b
No known key found for this signature in database
GPG key ID: 17CF79474E257545
5 changed files with 83 additions and 2 deletions

View file

@ -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)