Documentation
¶
Overview ¶
router.go Copyright (C) 2024 veypi <i@veypi.com> 2024-08-07 13:45 Distributed under terms of the MIT license.
Index ¶
- Variables
- type ApiHandler
- type Application
- type ErrHandle
- type Params
- type RestConf
- type Router
- type X
- func (x *X) GetRemoteIp() string
- func (x *X) Header() http.Header
- func (x *X) JSON(data any) error
- func (x *X) Next(args ...any) (err error)
- func (x *X) Parse(obj any) error
- func (x *X) SetParam(k string, v string)
- func (x *X) Stop()
- func (x *X) Write(p []byte) (n int, err error)
- func (x *X) WriteHeader(statusCode int)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type ApiHandler ¶ added in v0.6.0
type ApiHandler interface { fc0 | fc1 | fc2 | fc3 | fc4 | fc5 | fc6 }
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
func New ¶
func New(c *RestConf) (*Application, error)
func (*Application) Domain ¶ added in v0.6.0
func (app *Application) Domain(d string) Router
func (*Application) Router ¶
func (app *Application) Router() Router
func (*Application) Run ¶
func (app *Application) Run() error
func (*Application) ServeHTTP ¶ added in v0.6.0
func (app *Application) ServeHTTP(w http.ResponseWriter, r *http.Request)
func (*Application) SetMux ¶ added in v0.6.0
func (app *Application) SetMux(m func(w http.ResponseWriter, r *http.Request) func(http.ResponseWriter, *http.Request))
type RestConf ¶
type RestConf struct { Host string `json:"host"` Port int `json:"port"` // log file path LoggerPath string `json:"logger_path,omitempty"` LoggerLevel string `json:"logger_level,omitempty"` PrettyLog bool `json:"pretty_log,omitempty"` TimeFormat string `json:"time_format,omitempty"` PostMaxMemory uint TlsCfg *tls.Config MaxConnections int }
type Router ¶ added in v0.6.0
type Router interface { String() string Print() ServeHTTP(http.ResponseWriter, *http.Request) SubRouter(prefix string) Router Set(url string, method string, handlers ...any) Router Get(url string, handlers ...any) Router Any(url string, handlers ...any) Router Post(url string, handlers ...any) Router Head(url string, handlers ...any) Router Put(url string, handlers ...any) Router Patch(url string, handlers ...any) Router Delete(url string, handlers ...any) Router Use(middleware ...any) SetErrFunc(fc ErrHandle) Static(prefix string, directory string) EmbedFile(prefix string, f []byte) EmbedDir(prefix string, fs embed.FS, fsPrefix string, file404 string) }
type X ¶
func (*X) GetRemoteIp ¶ added in v0.6.0
func (*X) Parse ¶ added in v0.6.0
从不同来源解析目标结构体一级字段 tag标签 parse:"path/header/query/form/json" 可以追加为 path@alias_name tag标签 default:"" 字段为指针类型时为可选参数,defalt标签不生效 字段为非指针类型时是必选参数,default标签生效,未设置该值且未发现参数时报参数缺失错误 json 字段由json解码控制,没有default机制
func (*X) WriteHeader ¶ added in v0.6.0
Click to show internal directories.
Click to hide internal directories.