wc

package
v0.1.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

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 (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 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 (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 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 JSON

type JSON struct {
	Data any
}

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 (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) Args

func (r *Request) Args(args ...Arg) ArgScanner

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

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

func (*Request) ReadFromBody

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

func (*Request) SetPaginationHeader

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

func (*Request) WantsPartial added in v0.1.1

func (r *Request) WantsPartial() bool

type Route

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

func DELETE

func DELETE(name, localpath string, pathArgs ...PathArg) *Route

func GET

func GET(name, localpath string, pathArgs ...PathArg) *Route
func HEAD(name, localpath string, pathArgs ...PathArg) *Route

func OPTIONS

func OPTIONS(name, localpath string, pathArgs ...PathArg) *Route

func PATCH

func PATCH(name, localpath string, pathArgs ...PathArg) *Route

func POST

func POST(name, localpath string, pathArgs ...PathArg) *Route

func PUT

func PUT(name, localpath string, pathArgs ...PathArg) *Route

func (*Route) Call

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

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

func (*Route) HasHandler

func (r *Route) HasHandler() bool
func (r *Route) Link(argVals ...ArgValue) Link

func (*Route) Method

func (r *Route) Method() string

func (*Route) Mount

func (r *Route) Mount(comp *WebComponent)

func (*Route) MountPath added in v0.0.6

func (r *Route) MountPath() string

func (Route) Name

func (r Route) Name() string

func (*Route) Path

func (r *Route) Path() string

func (*Route) ServeHTTP

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

func (*Route) SetArgs

func (r *Route) SetArgs(args ...Arg) *Route

func (*Route) SetHandler

func (r *Route) SetHandler(fn func(*Request) (Content, error))

func (*Route) URL added in v0.0.7

func (r *Route) URL(argVals ...ArgValue) string

panics when arg is missing

type Status

type Status int

func (Status) Error

func (e Status) Error() string

type Text

type Text struct {
	Data string
}

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 WebComponent

type WebComponent struct {
	Name string

	Routes     []routeHandler
	MountPoint string
	// contains filtered or unexported fields
}

func New

func New(name, localpath string) *WebComponent

func (*WebComponent) HandleError

func (c *WebComponent) HandleError(r *Route, req *Request, wr http.ResponseWriter, err error) (writeBody bool)

func (*WebComponent) Mount

func (c *WebComponent) Mount(rt *router.Router)

func (*WebComponent) Path

func (c *WebComponent) Path() string

func (*WebComponent) ServeContent added in v0.1.1

func (c *WebComponent) ServeContent(r *Route, content Content, wr http.ResponseWriter, req *Request)

func (*WebComponent) SetErrorHandler added in v0.1.3

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

func (*WebComponent) SetLayouter added in v0.1.1

func (c *WebComponent) SetLayouter(fn func(r *Route, req *Request, inner html.Htmler) html.Html)

func (*WebComponent) SetRoutes

func (c *WebComponent) SetRoutes(routes ...routeHandler)

func (*WebComponent) Use

func (c *WebComponent) Use(fns ...func(http.Handler) http.Handler)

type XML

type XML struct {
	Data any
}

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

Jump to

Keyboard shortcuts

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