urest

package
v0.7.22 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthBearer added in v0.5.3

func AuthBearer(h http.Header) (string, bool, error)

func AuthDelete added in v0.5.3

func AuthDelete[Account any, Session any, RequestData any, ResponseData any](
	ctx *AuthContext[Account, Session],
	url string,
	handle func(AuthRequest[Account, Session, RequestData], *Response[ResponseData]),
)

func AuthGet added in v0.5.3

func AuthGet[Account any, Session any, RequestData any, ResponseData any](
	ctx *AuthContext[Account, Session],
	url string,
	handle func(AuthRequest[Account, Session, RequestData], *Response[ResponseData]),
)

func AuthHandle added in v0.5.3

func AuthHandle[Account any, Session any, RequestData any, ResponseData any](
	ctx *AuthContext[Account, Session],
	method string,
	url string,
	handle func(AuthRequest[Account, Session, RequestData], *Response[ResponseData]),
)

func AuthJwt added in v0.5.3

func AuthJwt[Account any, Session any](jwt *ujwt.Jwt[Account, Session], validate func(Session, string) error) func(http.Header) (Account, Session, bool, error)

func AuthKey added in v0.5.3

func AuthKey[Account any, Session any](name string, f func(string) (Account, error)) func(http.Header) (Account, Session, bool, error)

func AuthPost added in v0.5.3

func AuthPost[Account any, Session any, RequestData any, ResponseData any](
	ctx *AuthContext[Account, Session],
	url string,
	handle func(AuthRequest[Account, Session, RequestData], *Response[ResponseData]),
)

func AuthPut added in v0.5.3

func AuthPut[Account any, Session any, RequestData any, ResponseData any](
	ctx *AuthContext[Account, Session],
	url string,
	handle func(AuthRequest[Account, Session, RequestData], *Response[ResponseData]),
)

func AuthToken added in v0.5.3

func AuthToken(h http.Header, name string) (token string, present bool, err error)

func Delete added in v0.5.3

func Delete[RequestData any, ResponseData any](
	ctx *Context,
	url string,
	handle func(Request[RequestData], *Response[ResponseData]),
)

func Get added in v0.5.3

func Get[RequestData any, ResponseData any](
	ctx *Context,
	url string,
	handle func(Request[RequestData], *Response[ResponseData]),
)

func Handle

func Handle[RequestData any, ResponseData any](
	ctx *Context,
	method string,
	url string,
	header func(http.Header, *Response[ResponseData]),
	handle func(Request[RequestData], *Response[ResponseData]),
)

func Post added in v0.5.3

func Post[RequestData any, ResponseData any](
	ctx *Context,
	url string,
	handle func(Request[RequestData], *Response[ResponseData]),
)

func Put added in v0.5.3

func Put[RequestData any, ResponseData any](
	ctx *Context,
	url string,
	handle func(Request[RequestData], *Response[ResponseData]),
)

func Trace added in v0.5.3

func Trace[RequestData any, ResponseData any](ctx *Context, r Request[RequestData], w Response[ResponseData], tm time.Duration)

Types

type AuthContext added in v0.5.3

type AuthContext[Account any, Session any] struct {
	Base *Context
	// contains filtered or unexported fields
}

func NewAuthContext added in v0.5.3

func NewAuthContext[Account any, Session any](base *Context, auth func(h http.Header) (Account, Session, bool, error)) *AuthContext[Account, Session]

func (*AuthContext[Account, Session]) AppendAuth added in v0.5.3

func (o *AuthContext[Account, Session]) AppendAuth(auth func(h http.Header) (Account, Session, bool, error)) *AuthContext[Account, Session]

func (*AuthContext[Account, Session]) Auth added in v0.5.3

func (o *AuthContext[Account, Session]) Auth(h http.Header) (account Account, session Session, err error)

func (AuthContext[Account, Session]) Branch added in v0.5.3

func (o AuthContext[Account, Session]) Branch(name string) *AuthContext[Account, Session]

func (AuthContext[Account, Session]) Router added in v0.5.9

func (o AuthContext[Account, Session]) Router() *uhttp.Router

type AuthRequest added in v0.5.3

type AuthRequest[Account any, Session any, T any] struct {
	Account Account
	Session Session
	Request[T]
}

type Context

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

func NewContext

func NewContext(router *uhttp.Router) *Context

func (*Context) AllowCors

func (o *Context) AllowCors(v bool) *Context

func (Context) Branch

func (o Context) Branch(name string) *Context

func (*Context) Log added in v0.5.3

func (o *Context) Log() *ulog.Log

func (*Context) ReverseProxy added in v0.7.9

func (o *Context) ReverseProxy(path string, proxy *uhttp.ReverseProxy)

func (*Context) Router added in v0.5.9

func (o *Context) Router() *uhttp.Router

func (*Context) Trace added in v0.5.3

func (o *Context) Trace(v uhttp.FormatProvider, ok bool)

func (*Context) WithFormat added in v0.5.3

func (o *Context) WithFormat(f uhttp.Format) *Context

func (*Context) WithFormatError added in v0.5.3

func (o *Context) WithFormatError(f uhttp.Format) *Context

type Image

type Image struct {
	Type string
	Data []byte
}

type Request

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

func (Request[T]) ClientAddr

func (o Request[T]) ClientAddr() string

func (Request[T]) ClientHost

func (o Request[T]) ClientHost() string

func (*Request[T]) DataFromJson added in v0.5.3

func (o *Request[T]) DataFromJson() error

func (*Request[T]) DataFromParams

func (o *Request[T]) DataFromParams() error

func (Request[T]) EmptyData added in v0.5.3

func (o Request[T]) EmptyData() bool

func (Request[T]) HasBody added in v0.5.3

func (o Request[T]) HasBody() bool

func (Request[T]) HeaderString added in v0.5.3

func (o Request[T]) HeaderString() string

func (Request[T]) Param

func (o Request[T]) Param(name string) string

func (Request[T]) ParamBool

func (o Request[T]) ParamBool(name string) (bool, error)

func (Request[T]) ParamBoolDef

func (o Request[T]) ParamBoolDef(name string) (r bool, err error)

func (Request[T]) ParamExists

func (o Request[T]) ParamExists(name string) bool

func (Request[T]) ParamInt

func (o Request[T]) ParamInt(name string) (int, error)

func (Request[T]) ParamInt64

func (o Request[T]) ParamInt64(name string) (int64, error)

func (Request[T]) ParamUuid

func (o Request[T]) ParamUuid(name string) (uuid.UUID, error)

func (Request[T]) Params

func (o Request[T]) Params(v any) error

func (Request[T]) RemoteAddr

func (o Request[T]) RemoteAddr() string

func (Request[T]) RemoteHost

func (o Request[T]) RemoteHost() string

func (Request[T]) Var

func (o Request[T]) Var(name string) string

func (Request[T]) VarInt

func (o Request[T]) VarInt(name string) (int, error)

func (Request[T]) VarInt64

func (o Request[T]) VarInt64(name string) (int64, error)

func (Request[T]) VarInt64Def

func (o Request[T]) VarInt64Def(name string) int64

func (Request[T]) VarIntDef

func (o Request[T]) VarIntDef(name string) int

func (Request[T]) VarUuid

func (o Request[T]) VarUuid(name string) (uuid.UUID, error)

type Response added in v0.7.9

type Response[T any] struct {
	Status    int
	Data      T
	Error     error
	ErrorCode int
	// contains filtered or unexported fields
}

func (*Response[T]) BadRequest added in v0.7.9

func (o *Response[T]) BadRequest(s string)

func (*Response[T]) BadRequestf added in v0.7.9

func (o *Response[T]) BadRequestf(s string, args ...any)

func (*Response[T]) EmptyData added in v0.7.9

func (o *Response[T]) EmptyData() bool

func (*Response[T]) Forbidden added in v0.7.9

func (o *Response[T]) Forbidden(s string)

func (*Response[T]) Forbiddenf added in v0.7.9

func (o *Response[T]) Forbiddenf(s string, args ...any)

func (*Response[T]) MuteError added in v0.7.9

func (o *Response[T]) MuteError()

func (*Response[T]) NotAcceptable added in v0.7.9

func (o *Response[T]) NotAcceptable(s string)

func (*Response[T]) NotAcceptablef added in v0.7.9

func (o *Response[T]) NotAcceptablef(s string, args ...any)

func (*Response[T]) NotFound added in v0.7.9

func (o *Response[T]) NotFound(s string)

func (*Response[T]) NotImplemented added in v0.7.9

func (o *Response[T]) NotImplemented(s string)

func (*Response[T]) NotImplementedf added in v0.7.9

func (o *Response[T]) NotImplementedf(s string, args ...any)

func (*Response[T]) NotTrace added in v0.7.9

func (o *Response[T]) NotTrace()

func (*Response[T]) Ok added in v0.7.9

func (o *Response[T]) Ok() bool

func (*Response[T]) RefineBadRequest added in v0.7.9

func (o *Response[T]) RefineBadRequest(prefix string) bool

func (*Response[T]) RefineError added in v0.7.9

func (o *Response[T]) RefineError(prefix string) bool

func (*Response[T]) RefineErrorf added in v0.7.9

func (o *Response[T]) RefineErrorf(s string, args ...any) bool

func (*Response[T]) ServiceUnavailable added in v0.7.9

func (o *Response[T]) ServiceUnavailable(s string)

func (*Response[T]) ServiceUnavailablef added in v0.7.9

func (o *Response[T]) ServiceUnavailablef(s string, args ...any)

func (*Response[T]) SetBadRequest added in v0.7.9

func (o *Response[T]) SetBadRequest()

func (*Response[T]) SetForbidden added in v0.7.9

func (o *Response[T]) SetForbidden()

func (*Response[T]) SetNotAcceptable added in v0.7.9

func (o *Response[T]) SetNotAcceptable()

func (*Response[T]) SetNotFound added in v0.7.9

func (o *Response[T]) SetNotFound()

func (*Response[T]) SetNotImplemented added in v0.7.9

func (o *Response[T]) SetNotImplemented()

func (*Response[T]) SetServiceUnavailable added in v0.7.9

func (o *Response[T]) SetServiceUnavailable()

func (*Response[T]) SetUnauthorized added in v0.7.9

func (o *Response[T]) SetUnauthorized()

func (*Response[T]) Unauthorized added in v0.7.9

func (o *Response[T]) Unauthorized(s string)

func (*Response[T]) Unauthorizedf added in v0.7.9

func (o *Response[T]) Unauthorizedf(s string, args ...any)

type Text

type Text string

func (*Text) Set

func (o *Text) Set(s string)

type Void

type Void struct{}

Jump to

Keyboard shortcuts

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