Skip to content

api ​

go
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 ​

DefaultCORSOrigins is used when CORS_ORIGINS is unset or empty.

go
const DefaultCORSOrigins = "*"

func CORS ​

go
func CORS(next http.Handler) http.Handler

CORS allows cross-origin requests from the comma-separated origins in CORS_ORIGINS. When CORS_ORIGINS is unset or empty, DefaultCORSOrigins is used.

func New ​

go
func New(router chi.Router, _ Deps) huma.API

New 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 ​

go
func RequestLogger(next http.Handler) http.Handler

RequestLogger is a global HTTP middleware that logs all incoming requests and their responses using the structured application logger (pkg/logger).

func SpecToYAML ​

go
func SpecToYAML(api huma.API) ([]byte, error)

SpecToYAML generates the OpenAPI spec in YAML format from a Huma API instance.

func ValidateNonNullableBody ​

go
func ValidateNonNullableBody(api huma.API, body any, raw []byte) error

ValidateNonNullableBody 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.

go
type Deps struct{}

type SlogEntry ​

SlogEntry implements chimiddleware.LogEntry to record request details and panics.

go
type SlogEntry struct {
    // contains filtered or unexported fields
}

func (*SlogEntry) Panic ​

go
func (e *SlogEntry) Panic(v interface{}, stack []byte)

Panic logs any unhandled panics captured by middleware.Recoverer.

func (*SlogEntry) Write ​

go
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.

go
type SlogFormatter struct{}

func (*SlogFormatter) NewLogEntry ​

go
func (f *SlogFormatter) NewLogEntry(r *http.Request) chimiddleware.LogEntry

NewLogEntry creates a new LogEntry for the incoming request.

Generated by gomarkdoc

Documentation follows the source. Planned contracts are marked explicitly.