rest

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler[Req any, Resp any](h func(context.Context, *Req) (*Resp, error)) weedhttp.HandlerFunc

Handler is a generic wrapper that converts a strongly-typed contract method into a weedhttp.HandlerFunc. It parses the JSON request body (if any), executes the handler, and writes the JSON response.

Types

type ContractError

type ContractError interface {
	error
	StatusCode() int
}

ContractError allows handlers to return specific HTTP status codes and messages.

func NewError

func NewError(status int, message string) ContractError

NewError creates a new ContractError with the specified status code and message.

type RouteMeta

type RouteMeta = meta.RouteMeta

RouteMeta is an alias for meta.RouteMeta for backward compatibility.

func Mount

func Mount(router *weedhttp.RouterGroup, name string, service any, middleware ...weedhttp.MiddlewareFunc) ([]RouteMeta, error)

Mount registers routes based on an interface definition. T must be an interface type. service must be an implementation of T. This allows true contract-driven design where the interface acts as the router contract.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL