wc

package
v0.12.6 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2025 License: BSD-3-Clause Imports: 20 Imported by: 3

Documentation

Index

Constants

View Source
const CookieSrc = "Cookie"
View Source
const FormSrc = "Form"
View Source
const HeaderSrc = "Header"
View Source
const PathSrc = "Path"
View Source
const QuerySrc = "Query"

Variables

View Source
var (
	StringArg = ArgType("string")
	IntArg    = ArgType("int")
	FloatArg  = ArgType("float")
	BoolArg   = ArgType("bool")
	JSONArg   = ArgType("json")
	XMLArg    = ArgType("xml")
)
View Source
var (
	ErrNotFound    = errors.Error("not found: %v")
	ErrUnexpected  = errors.Error("unexpected: %v")
	ErrInvalidType = errors.Error("invalid type: %T (expected %T)")
	ErrMissing     = errors.Error("missing: %s")
	ErrForbidden   = errors.Error("forbidden: %s")
)
View Source
var (
	ErrWrongContentType = errors.Error("wrong content type: %s (expected %s)")
	ErrValidation       = errors.Error("validation error: %w")
)
View Source
var (
	ErrArgNotFound     = errors.Error("argument with name %q could not be found")
	ErrArgExists       = errors.Error("argument with name %q already exists")
	ErrArgMissing      = errors.Error("missing argument %q of source %q")
	ErrArgNotInRequest = errors.Error("argument %q of type %s not in request")
	ErrArgUnknown      = errors.Error("unknown argument %q given")
	ErrArgInvalidType  = errors.Error("invalid type for argument %s: %T (expected %T)")
)
View Source
var (
	ErrPathArgNotRegistered           = errors.Error("path argument %q from path string %q not registered")
	ErrPathArgRegisteredWithWrongType = errors.Error("path argument %q from path string %q registered with wrong path type (%q)")
	ErrPathArgRegisteredNotInPath     = errors.Error("path argument %q registered, but not inside path string %q")
)
View Source
var (
	ErrClientRequest           = errors.Error("error while making a request as a client: %w")
	ErrFormArgsAndBody         = errors.Error("form arguments (%#v) and a body can't be passed at the same time")
	ErrBodyNotAllowedForMethod = errors.Error("transmitting a form for method %s is not allowed")
)
View Source
var (
	ErrFormArg = errors.Error("form argument %q given")
)
View Source
var HeaderArgPaginationCount = NewHeaderArg("Pagination-Count")
View Source
var HeaderArgPaginationLimit = NewHeaderArg("Pagination-Limit")
View Source
var HeaderArgPaginationPage = NewHeaderArg("Pagination-Page")

Functions

func BodyAsCSS added in v0.11.0

func BodyAsCSS(req *http.Request, res *string) error

func BodyAsHTML added in v0.11.0

func BodyAsHTML(req *http.Request, res *string) error

func BodyAsJSON added in v0.11.0

func BodyAsJSON(req *http.Request, objref any) error

func BodyAsJavascript added in v0.11.0

func BodyAsJavascript(req *http.Request, res *string) error

func BodyAsText added in v0.11.0

func BodyAsText(req *http.Request, res *string) error

func BodyAsXML added in v0.11.0

func BodyAsXML(req *http.Request, objref any) error

func GetContentFromRequest added in v0.11.0

func GetContentFromRequest(req *http.Request, content Content) error

func GetPaginationHeader added in v0.11.0

func GetPaginationHeader(r *http.Request, count, limit, page *int) error

func NewPath

func NewPath(path string, args ...ArgValue) string

func NewRequest

func NewRequest(method string, path string, body Content, args ...ArgValue) (*http.Request, error)

func NewURL

func NewURL(path string, args ...ArgValue) string

func PutPathArgsToCtx added in v0.11.0

func PutPathArgsToCtx(req *http.Request, args ...ArgValue) *http.Request

func ReadFromBody added in v0.11.0

func ReadFromBody(req *http.Request, content Content) error

func ServeContent added in v0.11.0

func ServeContent(c Content, rw http.ResponseWriter) error

func SetPaginationHeader added in v0.11.0

func SetPaginationHeader(rw http.ResponseWriter, count, limit, page int)

Types

type Arg

type Arg interface {
	Source() string
	Type() ArgType
	Name() string
	IsRequired() bool
	Set(s any) ArgValue
	ReadValue(req *http.Request) (string, error)
}

type ArgScanner

type ArgScanner interface {
	Scan(targets ...any) error
}

type ArgType

type ArgType string

func (ArgType) Get

func (pt ArgType) Get(value string, target any) error

type ArgValue

type ArgValue [3]string

func (ArgValue) Name

func (a ArgValue) Name() string

func (ArgValue) Source

func (a ArgValue) Source() string

func (ArgValue) Value

func (a ArgValue) Value() string

type Args

type Args []Arg

func (Args) Append

func (p Args) Append(args ...Arg) Args

func (Args) Find

func (p Args) Find(name string) (param Arg, found bool)

func (Args) Get

func (p Args) Get(name string) Arg

panics if no arg with the name is found

type CSS

type CSS struct {
	Data string
}

func NewCSS added in v0.1.9

func NewCSS(data string) *CSS

func (CSS) ContentType

func (s CSS) ContentType() string

func (*CSS) ReadFrom

func (t *CSS) ReadFrom(rd io.Reader) error

func (CSS) WriteTo

func (t CSS) WriteTo(wr io.Writer) error

type Content

type Content interface {
	ContentType() string
	WriteTo(w io.Writer) error
	ReadFrom(rd io.Reader) error
}

type Contexter added in v0.11.0

type Contexter interface {
	Route() Route
	Request() *http.Request
	ResponseWriter() http.ResponseWriter
}

type CookieArg added in v0.2.0

type CookieArg struct {
	// contains filtered or unexported fields
}

func NewCookieArg added in v0.2.0

func NewCookieArg(name string) CookieArg

func (CookieArg) IsRequired added in v0.2.0

func (CookieArg) IsRequired() bool

func (CookieArg) Name added in v0.2.0

func (p CookieArg) Name() string

func (CookieArg) ReadValue added in v0.2.0

func (p CookieArg) ReadValue(req *http.Request) (string, error)

func (CookieArg) Set added in v0.7.0

func (p CookieArg) Set(a any) ArgValue

here is a hack: we allow the path arguments to be set via string also (which is related), we never have a type for PathArgs and therefor don't check, when we want to parse them

func (CookieArg) Source added in v0.2.0

func (p CookieArg) Source() string

func (CookieArg) Type added in v0.2.0

func (p CookieArg) Type() ArgType

type CoreContext added in v0.11.0

type CoreContext struct {
	// contains filtered or unexported fields
}

func NewCoreContext added in v0.11.0

func NewCoreContext(rt Route, rw http.ResponseWriter, req *http.Request) *CoreContext

func (*CoreContext) BodyAsCSS added in v0.11.0

func (m *CoreContext) BodyAsCSS(res *string) error

func (*CoreContext) BodyAsHTML added in v0.11.0

func (m *CoreContext) BodyAsHTML(res *string) error

func (*CoreContext) BodyAsJSON added in v0.11.0

func (m *CoreContext) BodyAsJSON(object_ref any) error

func (*CoreContext) BodyAsJavascript added in v0.11.0

func (m *CoreContext) BodyAsJavascript(res *string) error

func (*CoreContext) BodyAsText added in v0.11.0

func (m *CoreContext) BodyAsText(res *string) error

func (*CoreContext) BodyAsXML added in v0.11.0

func (m *CoreContext) BodyAsXML(object_ref any) error

func (*CoreContext) GetPaginationHeader added in v0.11.0

func (m *CoreContext) GetPaginationHeader(count, limit, page *int) error

func (*CoreContext) HxRefreshOrRedirect added in v0.11.0

func (e *CoreContext) HxRefreshOrRedirect(url string) error

func (*CoreContext) HxWantsPartial added in v0.11.0

func (e *CoreContext) HxWantsPartial() bool

func (*CoreContext) IsHxBoosted added in v0.11.0

func (e *CoreContext) IsHxBoosted() bool

func (*CoreContext) IsHxHistoryRestoreRequest added in v0.11.0

func (e *CoreContext) IsHxHistoryRestoreRequest() bool

func (*CoreContext) IsHxRequest added in v0.11.0

func (e *CoreContext) IsHxRequest() bool

func (*CoreContext) MovedPermanently added in v0.11.0

func (m *CoreContext) MovedPermanently(url string) error

func (*CoreContext) MovedTemporary added in v0.11.0

func (m *CoreContext) MovedTemporary(url string) error

func (*CoreContext) Redirect added in v0.11.0

func (m *CoreContext) Redirect(url string) error

func (*CoreContext) Request added in v0.11.0

func (e *CoreContext) Request() *http.Request

func (*CoreContext) ResponseWriter added in v0.11.0

func (e *CoreContext) ResponseWriter() http.ResponseWriter

func (*CoreContext) Route added in v0.11.0

func (e *CoreContext) Route() Route

func (*CoreContext) Scan added in v0.11.0

func (m *CoreContext) Scan(targets ...any) error

func (*CoreContext) SendCSS added in v0.11.0

func (m *CoreContext) SendCSS(data string) error

func (*CoreContext) SendFormErrors added in v0.11.0

func (m *CoreContext) SendFormErrors(errMap errors.ErrMap) error

func (*CoreContext) SendHTML added in v0.11.0

func (m *CoreContext) SendHTML(data any) error

func (*CoreContext) SendHxRefresh added in v0.11.0

func (e *CoreContext) SendHxRefresh() error

func (*CoreContext) SendJSON added in v0.11.0

func (m *CoreContext) SendJSON(data any) error

func (*CoreContext) SendJavaScript added in v0.11.0

func (m *CoreContext) SendJavaScript(data string) error

func (*CoreContext) SendText added in v0.11.0

func (m *CoreContext) SendText(data string) error

func (*CoreContext) SendXML added in v0.11.0

func (m *CoreContext) SendXML(data any) error

func (*CoreContext) SetHeader added in v0.11.0

func (m *CoreContext) SetHeader(key, value string)

func (*CoreContext) SetPaginationHeader added in v0.11.0

func (m *CoreContext) SetPaginationHeader(count, limit, page int)

func (*CoreContext) Status added in v0.11.0

func (m *CoreContext) Status(code int) error

func (*CoreContext) StatusHtmxCancelPolling added in v0.11.0

func (m *CoreContext) StatusHtmxCancelPolling() error

func (*CoreContext) StatusNotFound added in v0.11.0

func (m *CoreContext) StatusNotFound() error

func (*CoreContext) StatusOK added in v0.11.0

func (m *CoreContext) StatusOK() error

type FormArg

type FormArg struct {
	// contains filtered or unexported fields
}

func NewFormArg

func NewFormArg(name string) FormArg

func (FormArg) Bool

func (p FormArg) Bool() FormArg

func (FormArg) Float

func (p FormArg) Float() FormArg

func (FormArg) Int

func (p FormArg) Int() FormArg

func (FormArg) IsRequired

func (p FormArg) IsRequired() bool

func (FormArg) JSON

func (p FormArg) JSON() FormArg

func (FormArg) Name

func (p FormArg) Name() string

func (FormArg) ReadValue

func (p FormArg) ReadValue(req *http.Request) (string, error)

func (FormArg) Set added in v0.7.0

func (p FormArg) Set(a any) ArgValue

here is a hack: we allow the path arguments to be set via string also (which is related), we never have a type for PathArgs and therefor don't check, when we want to parse them

func (FormArg) Source

func (p FormArg) Source() string

func (FormArg) String

func (p FormArg) String() FormArg

func (FormArg) Type

func (p FormArg) Type() ArgType

func (FormArg) XML

func (p FormArg) XML() FormArg

type FormArgOpt

type FormArgOpt struct {
	FormArg
}

func NewFormArgOpt

func NewFormArgOpt(name string) FormArgOpt

func (FormArgOpt) Bool

func (p FormArgOpt) Bool() FormArgOpt

func (FormArgOpt) Float

func (p FormArgOpt) Float() FormArgOpt

func (FormArgOpt) Int

func (p FormArgOpt) Int() FormArgOpt

func (FormArgOpt) IsRequired

func (p FormArgOpt) IsRequired() bool

func (FormArgOpt) JSON

func (p FormArgOpt) JSON() FormArgOpt

func (FormArgOpt) Name

func (p FormArgOpt) Name() string

func (FormArgOpt) ReadValue

func (p FormArgOpt) ReadValue(req *http.Request) (string, error)

func (FormArgOpt) Set added in v0.7.0

func (p FormArgOpt) Set(a any) ArgValue

here is a hack: we allow the path arguments to be set via string also (which is related), we never have a type for PathArgs and therefor don't check, when we want to parse them

func (FormArgOpt) Source

func (p FormArgOpt) Source() string

func (FormArgOpt) String

func (p FormArgOpt) String() FormArgOpt

func (FormArgOpt) Type

func (p FormArgOpt) Type() ArgType

func (FormArgOpt) XML

func (p FormArgOpt) XML() FormArgOpt

type HTML

type HTML struct {
	Data string
}

func NewHTML added in v0.1.9

func NewHTML(data any) *HTML

func (HTML) ContentType

func (s HTML) ContentType() string

func (*HTML) ReadFrom

func (t *HTML) ReadFrom(rd io.Reader) error

func (HTML) WriteTo

func (t HTML) WriteTo(wr io.Writer) error

type HandlerFunc added in v0.11.0

type HandlerFunc[T Contexter] func(T) error

type HeaderArg

type HeaderArg struct {
	// contains filtered or unexported fields
}

func NewHeaderArg

func NewHeaderArg(name string) HeaderArg

func (HeaderArg) IsRequired

func (HeaderArg) IsRequired() bool

func (HeaderArg) Name

func (p HeaderArg) Name() string

func (HeaderArg) ReadValue

func (p HeaderArg) ReadValue(req *http.Request) (string, error)

func (HeaderArg) Set added in v0.7.0

func (p HeaderArg) Set(a any) ArgValue

here is a hack: we allow the path arguments to be set via string also (which is related), we never have a type for PathArgs and therefor don't check, when we want to parse them

func (HeaderArg) Source

func (p HeaderArg) Source() string

func (HeaderArg) Type

func (p HeaderArg) Type() ArgType

type JSON

type JSON struct {
	Data any
}

func NewJSON added in v0.1.9

func NewJSON(data any) *JSON

func (JSON) ContentType

func (s JSON) ContentType() string

func (*JSON) ReadFrom

func (s *JSON) ReadFrom(rd io.Reader) error

func (*JSON) WriteTo

func (s *JSON) WriteTo(wr io.Writer) error

type JavaScript

type JavaScript struct {
	Data string
}

func NewJavaScript added in v0.1.9

func NewJavaScript(data string) *JavaScript

func (JavaScript) ContentType

func (s JavaScript) ContentType() string

func (*JavaScript) ReadFrom

func (t *JavaScript) ReadFrom(rd io.Reader) error

func (JavaScript) WriteTo

func (t JavaScript) WriteTo(wr io.Writer) error
type Link [2]string
func NewLink(url, name string) Link

func (Link) AHref added in v0.0.7

func (rl Link) AHref() *html.Element

func (Link) Name added in v0.0.7

func (rl Link) Name() string

func (Link) URL added in v0.0.7

func (rl Link) URL() string

type PathArg

type PathArg struct {
	// contains filtered or unexported fields
}

func NewPathArg

func NewPathArg(name string) PathArg

func (PathArg) InPath

func (p PathArg) InPath() string

func (PathArg) IsRequired

func (p PathArg) IsRequired() bool

func (PathArg) Name

func (p PathArg) Name() string

func (PathArg) ReadValue

func (p PathArg) ReadValue(req *http.Request) (string, error)

func (PathArg) Set added in v0.7.0

func (p PathArg) Set(a any) ArgValue

here is a hack: we allow the path arguments to be set via string also (which is related), we never have a type for PathArgs and therefor don't check, when we want to parse them

func (PathArg) Source

func (p PathArg) Source() string

func (PathArg) Type

func (p PathArg) Type() ArgType

type QueryArg

type QueryArg struct {
	// contains filtered or unexported fields
}

func NewQueryArg

func NewQueryArg(name string) QueryArg

func (QueryArg) Bool

func (p QueryArg) Bool() QueryArg

func (QueryArg) Float

func (p QueryArg) Float() QueryArg

func (QueryArg) Int

func (p QueryArg) Int() QueryArg

func (QueryArg) IsRequired

func (p QueryArg) IsRequired() bool

func (QueryArg) JSON

func (p QueryArg) JSON() QueryArg

func (QueryArg) Name

func (p QueryArg) Name() string

func (QueryArg) ReadValue

func (p QueryArg) ReadValue(req *http.Request) (string, error)

func (QueryArg) Set added in v0.7.0

func (p QueryArg) Set(a any) ArgValue

here is a hack: we allow the path arguments to be set via string also (which is related), we never have a type for PathArgs and therefor don't check, when we want to parse them

func (QueryArg) Source

func (p QueryArg) Source() string

func (QueryArg) String

func (p QueryArg) String() QueryArg

func (QueryArg) Type

func (p QueryArg) Type() ArgType

func (QueryArg) XML

func (p QueryArg) XML() QueryArg

type QueryArgOpt

type QueryArgOpt struct {
	QueryArg
}

func NewQueryArgOpt

func NewQueryArgOpt(name string) QueryArgOpt

func (QueryArgOpt) Bool

func (p QueryArgOpt) Bool() QueryArgOpt

func (QueryArgOpt) Float

func (p QueryArgOpt) Float() QueryArgOpt

func (QueryArgOpt) Int

func (p QueryArgOpt) Int() QueryArgOpt

func (QueryArgOpt) IsRequired

func (p QueryArgOpt) IsRequired() bool

func (QueryArgOpt) JSON

func (p QueryArgOpt) JSON() QueryArgOpt

func (QueryArgOpt) Name

func (p QueryArgOpt) Name() string

func (QueryArgOpt) ReadValue

func (p QueryArgOpt) ReadValue(req *http.Request) (string, error)

func (QueryArgOpt) Set added in v0.7.0

func (p QueryArgOpt) Set(a any) ArgValue

here is a hack: we allow the path arguments to be set via string also (which is related), we never have a type for PathArgs and therefor don't check, when we want to parse them

func (QueryArgOpt) Source

func (p QueryArgOpt) Source() string

func (QueryArgOpt) String

func (p QueryArgOpt) String() QueryArgOpt

func (QueryArgOpt) Type

func (p QueryArgOpt) Type() ArgType

func (QueryArgOpt) XML

func (p QueryArgOpt) XML() QueryArgOpt

type Route

type Route interface {
	Args() Args
	Method() string
	Link(name string, argVals ...ArgValue) Link
	URL(argVals ...ArgValue) string
	Path() string
	HasHandler() bool
	Call(body Content, args ...ArgValue) (*http.Request, error)
	MustCall(body Content, args ...ArgValue) *http.Request
	GetContent(response Content, args ...ArgValue) error
	GetContentWithPlayload(payload Content, response Content, args ...ArgValue) error
	Scan(req *http.Request, targets ...any) error
}

type RouteHandler added in v0.11.0

type RouteHandler[T Contexter] struct {
	// contains filtered or unexported fields
}

func (*RouteHandler[T]) Args added in v0.11.0

func (r *RouteHandler[T]) Args() Args

func (*RouteHandler[T]) Call added in v0.11.0

func (r *RouteHandler[T]) Call(payload Content, args ...ArgValue) (*http.Request, error)

func (*RouteHandler[T]) Do added in v0.11.0

func (r *RouteHandler[T]) Do(fn func(ctx T) error) *RouteHandler[T]

func (*RouteHandler[T]) GetContent added in v0.11.0

func (r *RouteHandler[T]) GetContent(response Content, args ...ArgValue) error

func (*RouteHandler[T]) GetContentWithPlayload added in v0.11.0

func (r *RouteHandler[T]) GetContentWithPlayload(payload Content, response Content, args ...ArgValue) error

func (*RouteHandler[T]) HasHandler added in v0.11.0

func (r *RouteHandler[T]) HasHandler() bool
func (r *RouteHandler[T]) Link(name string, argVals ...ArgValue) Link

func (*RouteHandler[T]) Method added in v0.11.0

func (r *RouteHandler[T]) Method() string

func (*RouteHandler[T]) Mount added in v0.11.0

func (r *RouteHandler[T]) Mount(comp *Router[T])

func (*RouteHandler[T]) MountPath added in v0.11.0

func (r *RouteHandler[T]) MountPath() string

func (*RouteHandler[T]) MustCall added in v0.11.0

func (r *RouteHandler[T]) MustCall(payload Content, args ...ArgValue) *http.Request

MustCall is like Call and panics on errors

func (*RouteHandler[T]) Path added in v0.11.0

func (r *RouteHandler[T]) Path() string

func (*RouteHandler[T]) Scan added in v0.11.0

func (r *RouteHandler[T]) Scan(req *http.Request, targets ...any) error

func (*RouteHandler[T]) ServeHTTP added in v0.11.0

func (r *RouteHandler[T]) ServeHTTP(wr http.ResponseWriter, req *http.Request)

func (*RouteHandler[T]) URL added in v0.11.0

func (r *RouteHandler[T]) URL(argVals ...ArgValue) string

panics when arg is missing

func (*RouteHandler[T]) WithArgs added in v0.11.0

func (r *RouteHandler[T]) WithArgs(args ...Arg) *RouteHandler[T]

type Router added in v0.3.0

type Router[T Contexter] struct {
	Name   string
	Routes []*RouteHandler[T]
	// contains filtered or unexported fields
}

func New

func New[T Contexter](name string, mkContext func(Route, http.ResponseWriter, *http.Request) T) *Router[T]

func (*Router[T]) DELETE added in v0.3.0

func (c *Router[T]) DELETE(localpath string) *RouteHandler[T]

func (*Router[T]) GET added in v0.3.0

func (c *Router[T]) GET(localpath string) *RouteHandler[T]

func (*Router[T]) HEAD added in v0.3.0

func (c *Router[T]) HEAD(localpath string) *RouteHandler[T]

func (*Router[T]) Mount added in v0.3.0

func (c *Router[T]) Mount(rt *router.Router, pathPrefix string)

func (*Router[T]) OPTIONS added in v0.3.0

func (c *Router[T]) OPTIONS(localpath string) *RouteHandler[T]

func (*Router[T]) PATCH added in v0.3.0

func (c *Router[T]) PATCH(localpath string) *RouteHandler[T]

func (*Router[T]) POST added in v0.3.0

func (c *Router[T]) POST(localpath string) *RouteHandler[T]

func (*Router[T]) PUT added in v0.3.0

func (c *Router[T]) PUT(localpath string) *RouteHandler[T]

func (*Router[T]) Path added in v0.3.0

func (c *Router[T]) Path() string

func (*Router[T]) SetErrorHandler added in v0.3.0

func (c *Router[T]) SetErrorHandler(fn func(r Route, ctx T, err error) (continueHandling bool))

func (*Router[T]) SetVerbose added in v0.9.0

func (c *Router[T]) SetVerbose() *Router[T]

func (*Router[T]) SubRouter added in v0.12.2

func (rt *Router[T]) SubRouter(name string, prefix string) *Router[T]

SubRouter returns a new router that is a copy of rt, but with a different name and empty/different routes and a prefix that is applied when mounting a subrouter can be mounted directly or via its parent (subrouter are tracked within their parents)

func (*Router[T]) Use added in v0.3.0

func (rt *Router[T]) Use(fn func(next func(T) error) func(T) error) *Router[T]

type Text

type Text struct {
	Data string
}

func NewText added in v0.1.9

func NewText(data string) *Text

func (Text) ContentType

func (s Text) ContentType() string

func (*Text) ReadFrom

func (t *Text) ReadFrom(rd io.Reader) error

func (Text) WriteTo

func (t Text) WriteTo(wr io.Writer) error

type XML

type XML struct {
	Data any
}

func NewXML added in v0.1.9

func NewXML(data any) *XML

func (XML) ContentType

func (s XML) ContentType() string

func (*XML) ReadFrom

func (s *XML) ReadFrom(rd io.Reader) error

func (*XML) WriteTo

func (s *XML) WriteTo(wr io.Writer) error

Jump to

Keyboard shortcuts

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