Documentation
¶
Index ¶
- Constants
- func EqualFold[S byteSeq](b, s S) bool
- func GetMIME(extension string) string
- func GetReqHeader[V GenericType](c *Context, key string, defaultValue ...V) V
- func IsObject(v interface{}) bool
- func StatusMessage(status int) string
- func Stringify(v interface{}) string
- func Trim[S byteSeq](s S, cutset byte) S
- func TrimLeft[S byteSeq](s S, cutset byte) S
- func TrimRight[S byteSeq](s S, cutset byte) S
- func UUID() string
- func UUIDv4() string
- type AttributeName
- type Context
- func (c *Context) Append(field string, values ...string)
- func (c *Context) Apply(ctl interface{}) error
- func (c *Context) AsciiJSON(code int, obj any)
- func (c *Context) ContextString() string
- func (c *Context) Data(code int, contentType string, data []byte)
- func (c *Context) DataFromReader(code int, contentLength int64, contentType string, reader io.Reader, ...)
- func (c *Context) Error(err error) *Error
- func (c *Context) File(filepath string)
- func (c *Context) FileAttachment(filepath, filename string)
- func (c *Context) Get(key string) (value any, exists bool)
- func (c *Context) GetBool(key string) (b bool)
- func (c *Context) GetDuration(key string) (d time.Duration)
- func (c *Context) GetFastContext() *fasthttp.RequestCtx
- func (c *Context) GetFloat64(key string) (f64 float64)
- func (c *Context) GetHeader(key string, defaultValue ...string) string
- func (c *Context) GetInt(key string) (i int)
- func (c *Context) GetInt64(key string) (i64 int64)
- func (c *Context) GetString(key string) (s string)
- func (c *Context) GetStringMap(key string) (sm map[string]any)
- func (c *Context) GetStringMapString(key string) (sms map[string]string)
- func (c *Context) GetStringMapStringSlice(key string) (smss map[string][]string)
- func (c *Context) GetStringSlice(key string) (ss []string)
- func (c *Context) GetTime(key string) (t time.Time)
- func (c *Context) GetUint(key string) (ui uint)
- func (c *Context) GetUint64(key string) (ui64 uint64)
- func (c *Context) HTML(code int, name string, obj any)
- func (c *Context) HTMLPure(code int, content string, obj any)
- func (c *Context) Injector() inject.Injector
- func (c *Context) IsFromLocal() bool
- func (c *Context) JSON(code int, obj any)
- func (c *Context) JSONP(data any, callback ...string)
- func (c *Context) Location(path string)
- func (c *Context) Map(i ...interface{}) inject.TypeMapper
- func (c *Context) MapTo(i interface{}, j interface{}) inject.TypeMapper
- func (c *Context) Method() string
- func (c *Context) MustGet(key string) any
- func (c *Context) Param(key string) string
- func (c *Context) Protocol() string
- func (c *Context) Provide(i interface{}) error
- func (c *Context) PureJSON(code int, obj any)
- func (c *Context) Redirect(code int, location string)
- func (c *Context) RemoteIP() string
- func (c *Context) Render(code int, r render.IRender)
- func (c *Context) SaveUploadFile(file *multipart.FileHeader, dst string) error
- func (c *Context) SendStatus(status int)
- func (c *Context) SendStream(stream io.Reader, size ...int) error
- func (c *Context) Set(key string, value any)
- func (c *Context) SetHeader(key, val string)
- func (c *Context) Status(code int)
- func (c *Context) Stream(step func(w *bufio.Writer))
- func (c *Context) String(code int, format string, values ...any)
- func (c *Context) Type(extension string, charset ...string)
- func (c *Context) Vary(fields ...string)
- func (c *Context) Write(p []byte) (int, error)
- func (c *Context) WriteString(s string)
- func (c *Context) Writef(f string, a ...any) (int, error)
- func (c *Context) XHR() bool
- func (c *Context) XML(code int, obj any)
- type Entry
- func (entry *Entry) Debug(args ...interface{})
- func (entry *Entry) Error(args ...interface{})
- func (entry *Entry) Fatal(args ...interface{})
- func (entry *Entry) Info(args ...interface{})
- func (entry *Entry) Panic(args ...interface{})
- func (entry *Entry) Trace(args ...interface{})
- func (entry *Entry) Warn(args ...interface{})
- type Error
- type ErrorType
- type Formatter
- type GenericType
- type GenericTypeFloat
- type GenericTypeInteger
- type GenericTypeIntegerSigned
- type GenericTypeIntegerUnsigned
- type H
- type HandlerFunc
- type HookHandler
- type IMiddleware
- type IMiddlewareCtl
- type IMiddlewareGlobal
- type IMiddlewareMethod
- type JO
- type LogFileHook
- type Middleware
- func (m *Middleware) Attribute() AttributeName
- func (m *Middleware) GetParam() string
- func (m *Middleware) GetSlot() SlotType
- func (m *Middleware) Name() string
- func (m *Middleware) SetAttribute(attr AttributeName)
- func (m *Middleware) SetName(name string)
- func (m *Middleware) SetParam(p string)
- func (m *Middleware) SetSlot(slotType SlotType)
- type MiddlewareContainer
- func (m *MiddlewareContainer) GetByAttribute(slot string, attribute string) (IMiddleware, bool)
- func (m *MiddlewareContainer) GetByAttributeCtl(attribute string) (IMiddlewareCtl, bool)
- func (m *MiddlewareContainer) GetByAttributeMethod(attribute string) (IMiddlewareMethod, bool)
- func (m *MiddlewareContainer) GetGlobal(f func(middleware IMiddlewareGlobal) bool) bool
- func (m *MiddlewareContainer) Reg(middleware IMiddleware)
- func (m *MiddlewareContainer) VisitAll(slot string, f func(middleware IMiddleware) bool) bool
- type MiddlewareCtl
- type MiddlewareGlobal
- type MiddlewareMethod
- type PathMap
- type RootFields
- type RouteItem
- type Server
- type SlotType
- type WriterMap
Constants ¶
const MIMEOctetStream = "application/octet-stream"
const Version = "1.0.0-beta"
Variables ¶
This section is empty.
Functions ¶
func EqualFold ¶
func EqualFold[S byteSeq](b, s S) bool
EqualFold tests ascii strings or bytes for equality case-insensitively
func GetReqHeader ¶
func GetReqHeader[V GenericType](c *Context, key string, defaultValue ...V) V
GetReqHeader returns the HTTP request header specified by filed. This function is generic and can handle differnet headers type values.
func StatusMessage ¶
StatusMessage returns the correct message for the provided HTTP statuscode
func TrimLeft ¶
func TrimLeft[S byteSeq](s S, cutset byte) S
TrimLeft is the equivalent of strings/bytes.TrimLeft
Types ¶
type AttributeName ¶
type AttributeName = string
type Context ¶
type Context struct {
Keys map[string]any
Errors errorMsgs
ErrHandler func(*Context, error)
// contains filtered or unexported fields
}
func (*Context) Append ¶
Append the specified value to the HTTP response header field. If the header is not already set, it creates the header with the specified value.
func (*Context) ContextString ¶
ContextString returns unique string representation of the ctx.
The returned value may be useful for logging.
func (*Context) DataFromReader ¶
func (*Context) FileAttachment ¶
func (*Context) GetFastContext ¶
func (c *Context) GetFastContext() *fasthttp.RequestCtx
func (*Context) GetFloat64 ¶
func (*Context) GetHeader ¶
GetHeader returns the HTTP request header specified by field. Field names are case-insensitive Returned value is only valid within the handler. Do not store any references. Make copies or use the Immutable setting instead.
func (*Context) GetStringMapString ¶
func (*Context) GetStringMapStringSlice ¶
func (*Context) GetStringSlice ¶
func (*Context) IsFromLocal ¶
IsFromLocal will return true if request came from local.
func (*Context) Location ¶
Location sets the response Location HTTP header to the specified path parameter.
func (*Context) Map ¶
func (c *Context) Map(i ...interface{}) inject.TypeMapper
func (*Context) MapTo ¶
func (c *Context) MapTo(i interface{}, j interface{}) inject.TypeMapper
func (*Context) SaveUploadFile ¶ added in v0.1.1
func (c *Context) SaveUploadFile(file *multipart.FileHeader, dst string) error
func (*Context) SendStatus ¶
SendStatus sets the HTTP status code and if the response body is empty, it sets the correct status message in the body.
func (*Context) SendStream ¶
SendStream sets response body stream and optional body size.
func (*Context) SetHeader ¶
SetHeader sets the response's HTTP header field to the specified key, value.
func (*Context) Stream ¶
Stream sends a streaming response and returns a boolean indicates "Is client disconnected in middle of stream"
func (*Context) Type ¶
Type sets the Content-Type HTTP header to the MIME type specified by the file extension.
func (*Context) Vary ¶
Vary adds the given header field to the Vary response header. This will append the header, if not already listed, otherwise leaves it listed in the current location.
func (*Context) WriteString ¶
WriteString appends s to response body.
type ErrorType ¶
type ErrorType uint64
const ( // ErrorTypeBind is used when Context.Bind() fails. ErrorTypeBind ErrorType = 1 << 63 // ErrorTypeRender is used when Context.Render() fails. ErrorTypeRender ErrorType = 1 << 62 // ErrorTypePrivate indicates a private error. ErrorTypePrivate ErrorType = 1 << 0 // ErrorTypePublic indicates a public error. ErrorTypePublic ErrorType = 1 << 1 // ErrorTypeAny indicates any other error. ErrorTypeAny ErrorType = 1<<64 - 1 // ErrorTypeNu indicates any other error. ErrorTypeNu = 2 )
type Formatter ¶
type Formatter struct {
/** if enabled, the whole log will be marshaled to json (including captions)
work as json Formatter. */
TransportToJson bool
/** if enabled, log prefixed with 'timestamp, level' */
UseDefaultCaption bool
/** if enabled, CustomCaption will be marshaled to json */
CustomCaptionPrettyPrint bool
/** if has value, it attached right before message(object). custom caption can be struct, string, whatever */
CustomCaption interface{}
/** do PrettyPrint for message(object) */
PrettyPrint bool
/** if enabled, the message(object) will be colorized by predefined color code, along with logLevel */
Colorize bool
}
func Console ¶
func Console() *Formatter
* syntatic sugar for using formatter with predefined option (for console)
type GenericType ¶
type GenericType interface {
GenericTypeInteger | GenericTypeFloat | bool | string | []byte
}
type GenericTypeFloat ¶
type GenericTypeInteger ¶
type GenericTypeInteger interface {
GenericTypeIntegerSigned | GenericTypeIntegerUnsigned
}
type H ¶
func (H) MarshalXML ¶
type HandlerFunc ¶
type HandlerFunc = func(*Context)
type HookHandler ¶
type HookHandler interface {
HandleServerInfo(si []string)
HandleStructs(ctl *astp.Struct)
HandleParams(pf *astp.ParamField)
}
type IMiddleware ¶
type IMiddleware interface {
// Name returns middleware's name
Name() string
// Attribute returns middleware's Attribute just like Websocket so that you can use it like // @Websocket
Attribute() AttributeName
// GetSlot returns slot type
GetSlot() SlotType
// SetParam pass params (strings with query format) to middleware
SetParam(p string)
// GetParam return params string
GetParam() string
// contains filtered or unexported methods
}
IMiddleware interface of middleware
type IMiddlewareCtl ¶
type IMiddlewareCtl interface {
IMiddlewareMethod
// CloneAsCtl returns a copy from Middleware Container
CloneAsCtl() IMiddlewareCtl
// HandlerController will be called when handling controller
// returns a RouteItem(field `Path` is not empty) if you want to register a route
HandlerController(base string) *RouteItem
}
type IMiddlewareGlobal ¶
type IMiddlewareGlobal interface {
IMiddlewareCtl
}
type IMiddlewareMethod ¶
type IMiddlewareMethod interface {
IMiddleware
// CloneAsMethod returns a copy from Middleware Container
CloneAsMethod() IMiddlewareMethod
// HandlerMethod will be called when wrap a method
HandlerMethod(next HandlerFunc) HandlerFunc
}
type LogFileHook ¶
type LogFileHook struct {
// contains filtered or unexported fields
}
func NewFileHook ¶
func NewFileHook(output interface{}, formatter logrus.Formatter) *LogFileHook
func (*LogFileHook) Levels ¶
func (hook *LogFileHook) Levels() []logrus.Level
func (*LogFileHook) SetDefaultPath ¶
func (hook *LogFileHook) SetDefaultPath(defaultPath string)
func (*LogFileHook) SetDefaultWriter ¶
func (hook *LogFileHook) SetDefaultWriter(defaultWriter io.Writer)
func (*LogFileHook) SetFormatter ¶
func (hook *LogFileHook) SetFormatter(formatter logrus.Formatter)
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
func NewMiddleware ¶
func NewMiddleware(name string, slot string, attr string) *Middleware
func (*Middleware) Attribute ¶
func (m *Middleware) Attribute() AttributeName
func (*Middleware) GetParam ¶
func (m *Middleware) GetParam() string
func (*Middleware) GetSlot ¶
func (m *Middleware) GetSlot() SlotType
func (*Middleware) Name ¶
func (m *Middleware) Name() string
func (*Middleware) SetAttribute ¶
func (m *Middleware) SetAttribute(attr AttributeName)
func (*Middleware) SetName ¶
func (m *Middleware) SetName(name string)
func (*Middleware) SetParam ¶
func (m *Middleware) SetParam(p string)
func (*Middleware) SetSlot ¶
func (m *Middleware) SetSlot(slotType SlotType)
type MiddlewareContainer ¶
type MiddlewareContainer struct {
// contains filtered or unexported fields
}
MiddlewareContainer stores middlewares global middlewares will be stored with its Name as key
func NewMiddlewareContainer ¶
func NewMiddlewareContainer() *MiddlewareContainer
func (*MiddlewareContainer) GetByAttribute ¶
func (m *MiddlewareContainer) GetByAttribute(slot string, attribute string) (IMiddleware, bool)
GetByAttribute returns middleware with specified slot and attr.
func (*MiddlewareContainer) GetByAttributeCtl ¶
func (m *MiddlewareContainer) GetByAttributeCtl(attribute string) (IMiddlewareCtl, bool)
GetByAttributeCtl find controller middleware(IMiddlewareCtl) with attribute name
func (*MiddlewareContainer) GetByAttributeMethod ¶
func (m *MiddlewareContainer) GetByAttributeMethod(attribute string) (IMiddlewareMethod, bool)
GetByAttributeMethod find method middleware(IMiddlewareMethod) with attribute name
func (*MiddlewareContainer) GetGlobal ¶
func (m *MiddlewareContainer) GetGlobal(f func(middleware IMiddlewareGlobal) bool) bool
GetGlobal iterate global middlewares stop at `f` returns true
func (*MiddlewareContainer) Reg ¶
func (m *MiddlewareContainer) Reg(middleware IMiddleware)
Reg will store middleware to specified map according to its slot
func (*MiddlewareContainer) VisitAll ¶
func (m *MiddlewareContainer) VisitAll(slot string, f func(middleware IMiddleware) bool) bool
VisitAll visit all middlewares with the specified slot if f returns true, the loop will terminate
type MiddlewareCtl ¶
type MiddlewareCtl struct {
*Middleware
}
func NewMiddlewareCtl ¶
func NewMiddlewareCtl(name string, attr string) *MiddlewareCtl
type MiddlewareGlobal ¶
type MiddlewareGlobal struct {
*Middleware
}
func NewMiddlewareGlobal ¶
func NewMiddlewareGlobal(name string) *MiddlewareGlobal
type MiddlewareMethod ¶
type MiddlewareMethod struct {
*Middleware
}
func NewMiddlewareMethod ¶
func NewMiddlewareMethod(name string, attr string) *MiddlewareMethod
type RootFields ¶
type RouteItem ¶
type RouteItem struct {
Method string // HTTP METHOD
Path string // route path
IsHide bool // if set true, this route will not show in route table
H HandlerFunc // handler for this route
Middleware IMiddlewareMethod // just refer to middleware itself
}
func EmptyRouteItem ¶
func EmptyRouteItem(m IMiddlewareMethod) *RouteItem
EmptyRouteItem returns an empty RouteItem which won't register route
type Server ¶
func (*Server) RegisterHooks ¶
func (s *Server) RegisterHooks(handler HookHandler)
func (*Server) RegisterRoute ¶
func (*Server) RegisterRoutes ¶
func (*Server) Use ¶
func (s *Server) Use(middleware IMiddleware)
Use register middleware to server. you can only use the @'Attribute' after register a middleware