Documentation
¶
Index ¶
- Constants
- Variables
- func AddServices(prefix string, opts opt.ServicesFuncArr, wss ...NS)
- func AuthFilter(code int, i *auth.Instance) restful.FilterFunction
- func DefaultErrorTransformer(c *Container) func(ctx box.Ctx)
- func DefaultResponseTransformer(ctx box.Ctx)
- func Filter(f func(ctx box.Ctx)) restful.FilterFunction
- func FilterWithLogger(f func(ctx box.Ctx), logger *slog.Logger) restful.FilterFunction
- func Handle(f func(ctx box.Ctx)) restful.RouteFunction
- func HandleWithLogger(f func(ctx box.Ctx), logger *slog.Logger) restful.RouteFunction
- func ListenAndServe(srv *http.Server, addrChan chan<- string) error
- func ListenAndServeTLS(srv *http.Server, addrChan chan<- string) error
- func LogFilter(c ...*Container) restful.FilterFunction
- func NewSwaggerService(info SwaggerInfo) *restful.WebService
- func Run(addr string, opts ...opt.RunFunc)
- func WrapHandler(f func(ctx box.Ctx)) http.HandlerFunc
- type Container
- func (c *Container) AddServices(prefix string, opts opt.ServicesFuncArr, wss ...NS)
- func (c *Container) DefaultErrorTransformer() *Container
- func (c *Container) DefaultLogFilter() *Container
- func (c *Container) DefaultResponseTransformer() *Container
- func (c *Container) ErrorMap() map[int]string
- func (c *Container) FilterFunc(f func(ctx box.Ctx)) restful.FilterFunction
- func (c *Container) Handle(f func(ctx box.Ctx)) restful.RouteFunction
- func (c *Container) NewSwaggerService(info SwaggerInfo) *restful.WebService
- func (c *Container) NewTestServer() *TestServer
- func (c *Container) NewWS() WS
- func (c *Container) RouteAPI(f any, opts ...opt.RouteAPIOpts) opt.RouteFunc
- func (c *Container) RouteIDMap() map[string]string
- func (c *Container) Run(addr string, opts ...opt.RunFunc)
- func (c *Container) SetLogger(logger *slog.Logger) *Container
- type CtlInterface
- type NS
- type SwaggerInfo
- type TestServer
- type WS
Constants ¶
const ( // MIME_HTML_FORM is application/x-www-form-urlencoded header MIME_HTML_FORM = "application/x-www-form-urlencoded" // MIME_FILE_FORM is multipart/form-data MIME_FILE_FORM = "multipart/form-data" )
Variables ¶
var AutoGenPathDoc = true
var DefaultContainer = New(restful.DefaultContainer)
Functions ¶
func AddServices ¶
func AddServices(prefix string, opts opt.ServicesFuncArr, wss ...NS)
AddServices adds services with namespace.
func AuthFilter ¶
func AuthFilter(code int, i *auth.Instance) restful.FilterFunction
AuthFilter checks if request contains JWT, and sets UserID in Attribute if exists,
func DefaultErrorTransformer ¶ added in v0.5.15
func DefaultResponseTransformer ¶ added in v0.5.15
func Filter ¶
func Filter(f func(ctx box.Ctx)) restful.FilterFunction
Filter transform a biu handler to a restful.FilterFunction
func FilterWithLogger ¶ added in v0.5.0
func Handle ¶
func Handle(f func(ctx box.Ctx)) restful.RouteFunction
Handle transform a biu handler to a restful.RouteFunction.
func HandleWithLogger ¶ added in v0.5.0
func ListenAndServe ¶ added in v0.3.6
ListenAndServe listens on the TCP network address srv.Addr and then calls Serve to handle requests on incoming connections. Accepted connections are configured to enable TCP keep-alives. If srv.Addr is blank, ":http" is used. ListenAndServe always returns a non-nil error.
func ListenAndServeTLS ¶ added in v0.9.0
ListenAndServeTLS listens on TCP and serves TLS with the server's TLSConfig.
func LogFilter ¶
func LogFilter(c ...*Container) restful.FilterFunction
LogFilter logs
{
remote_addr,
method,
uri,
proto,
status_code,
content_length,
}
for each request
func NewSwaggerService ¶
func NewSwaggerService(info SwaggerInfo) *restful.WebService
NewSwaggerService creates a swagger webservice in /swagger
func WrapHandler ¶
func WrapHandler(f func(ctx box.Ctx)) http.HandlerFunc
WrapHandler wraps a biu handler to http.HandlerFunc
Types ¶
type Container ¶
Container of restful
func NewContainer ¶ added in v0.5.15
NewContainer creates a new restful container.
func (*Container) AddServices ¶
func (c *Container) AddServices(prefix string, opts opt.ServicesFuncArr, wss ...NS)
AddServices adds services with namespace for container.
func (*Container) DefaultErrorTransformer ¶ added in v0.6.5
DefaultErrorTransformer is a chainable api.
func (*Container) DefaultLogFilter ¶ added in v0.6.5
DefaultLogFilter is a chainable api.
func (*Container) DefaultResponseTransformer ¶ added in v0.6.5
DefaultResponseTransformer is a chainable api.
func (*Container) FilterFunc ¶ added in v0.5.0
func (c *Container) FilterFunc(f func(ctx box.Ctx)) restful.FilterFunction
FilterFunc transform a biu handler to a restful.FilterFunction
func (*Container) Handle ¶ added in v0.5.0
func (c *Container) Handle(f func(ctx box.Ctx)) restful.RouteFunction
func (*Container) NewSwaggerService ¶
func (c *Container) NewSwaggerService(info SwaggerInfo) *restful.WebService
NewSwaggerService creates a swagger webservice in /swagger
func (*Container) NewTestServer ¶ added in v0.2.0
func (c *Container) NewTestServer() *TestServer
NewTestServer returns a Test Server.
func (*Container) RouteIDMap ¶ added in v0.5.15
type CtlInterface ¶
type CtlInterface interface {
WebService(WS)
}
CtlInterface is the interface of controllers
type NS ¶
type NS struct {
NameSpace string // url parent of controller
Controller CtlInterface // controller implement CtlInterface
Desc string // description of controller of namespace
ExternalDesc string // external documentation of controller
ExternalURL string // external url of ExternalDesc
}
NS contains configuration of a namespace
type SwaggerInfo ¶
type SwaggerInfo struct {
Title string
Description string
TermsOfService string
ContactName string
ContactURL string
ContactEmail string
LicenseName string
LicenseURL string
Version string
WebServicesURL string
DisableCORS bool
// swagger service will be running under
// http://<api>/<RoutePrefix>/<RouteSuffix>
// by default the RouteSuffix is swagger
RoutePrefix string
RouteSuffix string
}
SwaggerInfo contains configuration of swagger documents.
type TestServer ¶ added in v0.2.0
TestServer wraps a httptest.Server
func NewTestServer ¶ added in v0.2.0
func NewTestServer() *TestServer
NewTestServer returns a Test Server.
type WS ¶
type WS struct {
*restful.WebService
*Container
// contains filtered or unexported fields
}
WS extends *restful.WebService
