wc

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: BSD-3-Clause Imports: 19 Imported by: 0

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"
View Source
const StatusOK = Status(200)

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 MovedPermanently

func MovedPermanently(url string) statusRedirect

MovedPermanently e.g. whole webpage moved

func MovedTemporary

func MovedTemporary(url string) statusRedirect

MovedTemporary e.g. for maintenance

func NewPath

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

func NewURL

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

func Redirect

func Redirect(url string) statusRedirect

Types

type Arg

type Arg interface {
	Source() string
	Type() ArgType
	Name() string
	IsRequired() bool
	Value(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 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) Source added in v0.2.0

func (p CookieArg) Source() string

func (CookieArg) Type added in v0.2.0

func (p CookieArg) Type() ArgType

func (CookieArg) Value added in v0.2.0

func (p CookieArg) Value(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

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) Source

func (p FormArg) Source() string

func (FormArg) String

func (p FormArg) String() FormArg

func (FormArg) Type

func (p FormArg) Type() ArgType

func (FormArg) Value

func (p FormArg) Value(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) 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) Source

func (p FormArgOpt) Source() string

func (FormArgOpt) String

func (p FormArgOpt) String() FormArgOpt

func (FormArgOpt) Type

func (p FormArgOpt) Type() ArgType

func (FormArgOpt) Value

func (p FormArgOpt) Value(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) 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 Handler added in v0.3.3

type Handler struct {
	http.Handler
}

Handler allows to wrap an http.Handler and return it as an error the (fake) error does not do any harm and the http.Handler is called as ususal

func (Handler) Error added in v0.3.3

func (Handler) Error() string
type Header struct {
	Name  string
	Value string
}

func (Header) Error added in v0.3.4

func (e Header) Error() string

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) Source

func (p HeaderArg) Source() string

func (HeaderArg) Type

func (p HeaderArg) Type() ArgType

func (HeaderArg) Value

func (p HeaderArg) Value(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

type Headers added in v0.3.4

type Headers map[string]string

func (Headers) Error added in v0.3.4

func (e Headers) Error() string

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) Source

func (p PathArg) Source() string

func (PathArg) Type

func (p PathArg) Type() ArgType

func (PathArg) Value

func (p PathArg) Value(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

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) Source

func (p QueryArg) Source() string

func (QueryArg) String

func (p QueryArg) String() QueryArg

func (QueryArg) Type

func (p QueryArg) Type() ArgType

func (QueryArg) Value

func (p QueryArg) Value(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) 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) Source

func (p QueryArgOpt) Source() string

func (QueryArgOpt) String

func (p QueryArgOpt) String() QueryArgOpt

func (QueryArgOpt) Type

func (p QueryArgOpt) Type() ArgType

func (QueryArgOpt) Value

func (p QueryArgOpt) Value(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) XML

func (p QueryArgOpt) XML() QueryArgOpt

type Request

type Request struct {
	*http.Request
	// contains filtered or unexported fields
}

func NewRequest

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

func (*Request) BodyAsCSS

func (req *Request) BodyAsCSS(res *string) error

func (*Request) BodyAsHTML

func (req *Request) BodyAsHTML(res *string) error

func (*Request) BodyAsJSON

func (req *Request) BodyAsJSON(objref any) error

func (*Request) BodyAsJavascript

func (req *Request) BodyAsJavascript(res *string) error

func (*Request) BodyAsText

func (req *Request) BodyAsText(res *string) error

func (*Request) BodyAsXML

func (req *Request) BodyAsXML(objref any) error

func (*Request) GetPaginationHeader

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

func (*Request) HxWantsPartial added in v0.1.10

func (r *Request) HxWantsPartial() bool

func (*Request) IsHxBoosted added in v0.1.10

func (r *Request) IsHxBoosted() bool

func (*Request) IsHxHistoryRestoreRequest added in v0.1.10

func (r *Request) IsHxHistoryRestoreRequest() bool

func (*Request) IsHxRequest added in v0.1.10

func (r *Request) IsHxRequest() bool

func (*Request) PutPathArgsToCtx

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

func (*Request) ReadFromBody

func (req *Request) ReadFromBody(content Content) error

func (*Request) Scan added in v0.2.0

func (r *Request) Scan(targets ...any) error

func (*Request) SetPaginationHeader

func (r *Request) SetPaginationHeader(count, limit, page int)

type Route

type Route[T any] struct {
	// contains filtered or unexported fields
}

func (*Route[T]) Call

func (r *Route[T]) Call(body Content, args ...ArgValue) (Content, error)

Call allows a route to be called without the need of a real http request

func (*Route[T]) Do added in v0.2.0

func (r *Route[T]) Do(fn func(ctx T, req *Request) (Content, error)) *Route[T]

func (*Route[T]) HasHandler

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

func (*Route[T]) Method

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

func (*Route[T]) Mount

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

func (*Route[T]) MountPath added in v0.0.6

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

func (*Route[T]) Path

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

func (*Route[T]) ServeHTTP

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

func (*Route[T]) URL added in v0.0.7

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

panics when arg is missing

func (*Route[T]) WithArgs added in v0.2.0

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

type Router added in v0.3.0

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

func New

func New[T any](name string, startContext func(req *Request) (ctx T), stopContext func(ctx T, req *Request)) *Router[T]

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

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

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

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

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

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

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

func (c *Router[T]) HandleError(r *Route[T], req *Request, wr http.ResponseWriter, err error) (writeBody bool)

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) *Route[T]

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

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

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

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

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

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

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

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

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

func (c *Router[T]) ServeContent(r *Route[T], content Content, wr http.ResponseWriter, req *Request)

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

func (c *Router[T]) SetErrorHandler(fn func(r *Route[T], req *Request, wr http.ResponseWriter, err error) (continueHandling bool))

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

func (c *Router[T]) SetLayouter(fn func(r *Route[T], req *Request, inner html.Htmler) html.Html)

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

func (c *Router[T]) Use(fns ...func(http.Handler) http.Handler)

type Status

type Status int

func (Status) Error

func (e Status) Error() string

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

Directories

Path Synopsis
example/server command
example
server command

Jump to

Keyboard shortcuts

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