api
import "github.com/prescriptoo/prescriptoo-api/pkg/api"Package api provides the Open API documentation for the Prescriptoo service.
Package api provides the OpenAPI documentation and HTTP middleware for the Prescriptoo service.
Index
- Constants
- func CORS(next http.Handler) http.Handler
- func New(router chi.Router, _ Deps) huma.API
- func RequestLogger(next http.Handler) http.Handler
- func SpecToYAML(api huma.API) ([]byte, error)
- func ValidateNonNullableBody(api huma.API, body any, raw []byte) error
- type Deps
- type SlogEntry
- type SlogFormatter
Constants
DefaultCORSOrigins is used when CORS_ORIGINS is unset or empty.
const DefaultCORSOrigins = "*"func CORS
func CORS(next http.Handler) http.HandlerCORS allows cross-origin requests from the comma-separated origins in CORS_ORIGINS. When CORS_ORIGINS is unset or empty, DefaultCORSOrigins is used.
func New
func New(router chi.Router, _ Deps) huma.APINew creates a new instance of the Prescriptoo API with the provided router and dependencies. It configures the API with metadata, server information, and tags for better organization and understanding of the API endpoints.
func RequestLogger
func RequestLogger(next http.Handler) http.HandlerRequestLogger is a global HTTP middleware that logs all incoming requests and their responses using the structured application logger (pkg/logger).
func SpecToYAML
func SpecToYAML(api huma.API) ([]byte, error)SpecToYAML generates the OpenAPI spec in YAML format from a Huma API instance.
func ValidateNonNullableBody
func ValidateNonNullableBody(api huma.API, body any, raw []byte) errorValidateNonNullableBody rejects explicit nulls disallowed by an operation's schema. Huma v2.39 skips validation for null-valued optional object properties. This supplements that validation without conflating null, omission and empty arrays.
type Deps
Deps represents the dependencies required to create a new Prescriptoo API instance. Currently, it is an empty struct, but it can be extended in the future to include any necessary dependencies.
type Deps struct{}type SlogEntry
SlogEntry implements chimiddleware.LogEntry to record request details and panics.
type SlogEntry struct {
// contains filtered or unexported fields
}func (*SlogEntry) Panic
func (e *SlogEntry) Panic(v interface{}, stack []byte)Panic logs any unhandled panics captured by middleware.Recoverer.
func (*SlogEntry) Write
func (e *SlogEntry) Write(status, bytes int, _ http.Header, elapsed time.Duration, _ interface{})Write logs the completed request information.
type SlogFormatter
SlogFormatter implements chimiddleware.LogFormatter to bridge chi middleware with pkg/logger.
type SlogFormatter struct{}func (*SlogFormatter) NewLogEntry
func (f *SlogFormatter) NewLogEntry(r *http.Request) chimiddleware.LogEntryNewLogEntry creates a new LogEntry for the incoming request.
Generated by gomarkdoc