golazy.dev golazy.dev / lazyroutes Index | Files

package lazyroutes

import "golazy.dev/lazyroutes"

Functions

Types

type Action

type Action func(http.ResponseWriter, *http.Request) error

type Resource

type Resource struct {
	// contains filtered or unexported fields
}
func (r *Resource) Delete
func (r *Resource) Delete(path string, action any)
func (r *Resource) Get
func (r *Resource) Get(path string, action any)
func (r *Resource) MemberDelete
func (r *Resource) MemberDelete(path string, action any)
func (r *Resource) MemberGet
func (r *Resource) MemberGet(path string, action any)
func (r *Resource) MemberPatch
func (r *Resource) MemberPatch(path string, action any)
func (r *Resource) MemberPost
func (r *Resource) MemberPost(path string, action any)
func (r *Resource) MemberPut
func (r *Resource) MemberPut(path string, action any)
func (r *Resource) Param
func (r *Resource) Param(name string) *Resource
func (r *Resource) Patch
func (r *Resource) Patch(path string, action any)
func (r *Resource) Path
func (r *Resource) Path(path string) *Resource
func (r *Resource) Plural
func (r *Resource) Plural(name string) *Resource
func (r *Resource) Post
func (r *Resource) Post(path string, action any)
func (r *Resource) Put
func (r *Resource) Put(path string, action any)
func (r *Resource) Singular
func (r *Resource) Singular(name string) *Resource

type Route

Route is the metadata for one registered route.

type Route struct {
	Method		string		`json:"method"`
	Path		string		`json:"path"`
	Name		string		`json:"name"`
	Controller	string		`json:"controller,omitempty"`
	Action		string		`json:"action,omitempty"`
	Namespace	string		`json:"namespace,omitempty"`
	NamedParams	map[string]bool	`json:"params"`
}
func RouteFromContext

RouteFromContext returns the route metadata and parameter values attached to a request context.

func RouteFromContext(ctx context.Context) (Route, map[string]string, bool)
func RouteFromRequest

RouteFromRequest returns the route metadata and parameter values attached to the request context.

func RouteFromRequest(r *http.Request) (Route, map[string]string, bool)

type Scope

Scope is the routing DSL entrypoint used by application routes. It embeds the standard library ServeMux so the same object is directly usable as an http.Handler.

type Scope struct {
	*http.ServeMux
	Context	context.Context
	Routes	RouteTable
	// contains filtered or unexported fields
}
func New

New builds a scope with the framework's public-file fallback already wired.

func New(ctx context.Context) *Scope
func (s *Scope) As

As creates a child scope with a route-name prefix.

func (s *Scope) As(name string, draw ...func(*Scope)) *Scope
func (s *Scope) Delete
func (s *Scope) Delete(path string, controller any, action any)
func (s *Scope) Get
func (s *Scope) Get(path string, controller any, action any)
func (s *Scope) HandleFunc

HandleFunc registers a non-controller route action.

func (s *Scope) HandleFunc(method, path string, handlerAction Action)
func (s *Scope) HandlesPath
func (s *Scope) HandlesPath(path string) bool
func (s *Scope) Namespace

Namespace creates a child scope with path, route-name, and namespace prefixes.

func (s *Scope) Namespace(name string, draw ...func(*Scope)) *Scope
func (s *Scope) Patch
func (s *Scope) Patch(path string, controller any, action any)
func (s *Scope) Path

Path creates a child scope with a path prefix.

func (s *Scope) Path(path string, draw ...func(*Scope)) *Scope
func (s *Scope) PathFor

PathFor builds a path from a named route and route parameter values.

func (s *Scope) PathFor(name string, values ...any) (string, error)
func (s *Scope) Post
func (s *Scope) Post(path string, controller any, action any)
func (s *Scope) Put
func (s *Scope) Put(path string, controller any, action any)
func (s *Scope) RegisterHelpers

RegisterHelpers returns template helpers provided by the router.

func (s *Scope) RegisterHelpers() map[string]any
func (s *Scope) Resources
func (s *Scope) Resources(controller any, configure ...func(*Resource)) *Resource