Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultGroup(prefix string, fn func(r *RouterGroup))
- func DefaultMiddleware(name string, fn func(app *Application))
- func GenerateRequestID() string
- type Application
- func (app *Application) Cache() *Cache
- func (app *Application) CreateJSONRPC(path string) jsonrpc.Server[*Context]
- func (app *Application) Cron() *Cron
- func (app *Application) Debug() *Debug
- func (app *Application) Fallback(h HandlerFunc)
- func (app *Application) IsProd() bool
- func (app *Application) NotFound(h HandlerFunc)
- func (app *Application) Queue() *Queue
- func (app *Application) Run(addr ...string) error
- func (app *Application) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (app *Application) SetTemplates(dir string, fns ...template.FuncMap)
- type Body
- type Cache
- type Context
- func (ctx *Context) AcceptHTML() bool
- func (ctx *Context) AcceptJSON() bool
- func (ctx *Context) AddHeader(key string, value string)
- func (ctx *Context) Authorization() string
- func (ctx *Context) BasicAuth() (username string, password string, ok bool)
- func (ctx *Context) BearerToken() (token string, ok bool)
- func (ctx *Context) BindForm(obj interface{}) error
- func (ctx *Context) BindHeader(obj interface{}) error
- func (ctx *Context) BindJSON(obj interface{}) error
- func (ctx *Context) BindParams(obj interface{}) error
- func (ctx *Context) BindQuery(obj interface{}) error
- func (ctx *Context) BindYAML(obj interface{}) error
- func (ctx *Context) Bodies() map[string]any
- func (ctx *Context) Body() *Body
- func (ctx *Context) Cache() *Cache
- func (ctx *Context) Cookie() *Cookie
- func (ctx *Context) Cookies() map[string]string
- func (ctx *Context) Cron() *Cron
- func (ctx *Context) Data(status int, contentType string, data []byte)
- func (ctx *Context) Debug() *Debug
- func (ctx *Context) Env() *Env
- func (ctx *Context) Error(status int, message string)
- func (ctx *Context) Fail(err error, code int, message string, status ...int)
- func (ctx *Context) FailWithError(err HTTPError)
- func (ctx *Context) Fetch() *fetch.Fetch
- func (ctx *Context) File(key string) (multipart.File, *multipart.FileHeader)
- func (ctx *Context) Files() map[string]*multipart.FileHeader
- func (ctx *Context) Form() *Form
- func (ctx *Context) Forms() *safe.Map
- func (ctx *Context) Get(key string) string
- func (ctx *Context) GetRawData() ([]byte, error)
- func (ctx *Context) HTML(code int, name string, data interface{})
- func (ctx *Context) Header() http.Header
- func (ctx *Context) Headers() *safe.Map
- func (ctx *Context) Host() string
- func (ctx *Context) IP() string
- func (ctx *Context) JSON(status int, obj interface{})
- func (ctx *Context) Next()
- func (ctx *Context) Origin() string
- func (ctx *Context) Param() *Param
- func (ctx *Context) Params() *safe.Map
- func (ctx *Context) Protocol() string
- func (ctx *Context) Queries() *safe.Map
- func (ctx *Context) Query() *Query
- func (ctx *Context) Queue() *Queue
- func (ctx *Context) Redirect(url string, status ...int)
- func (ctx *Context) Render(code int, name string, data interface{})
- func (ctx *Context) RequestID() string
- func (ctx *Context) SaveFile(key, path string) error
- func (ctx *Context) Session() *Session
- func (ctx *Context) Set(key string, value string)
- func (ctx *Context) SetHeader(key string, value string)
- func (ctx *Context) State() *State
- func (ctx *Context) Status(status int)
- func (ctx *Context) Stream() io.ReadCloser
- func (ctx *Context) String(status int, format string, values ...interface{})
- func (ctx *Context) Success(result interface{})
- func (ctx *Context) URL() string
- func (ctx *Context) User() *User
- func (ctx *Context) Write(b []byte)
- type Cookie
- type Cron
- func (c *Cron) AddDailyJob(name string, cmd func() error) (id int, err error)
- func (c *Cron) AddHourlyJob(name string, cmd func() error) (id int, err error)
- func (c *Cron) AddJob(name string, spec string, job func() error) (id int, err error)
- func (c *Cron) AddMinutelyJob(name string, cmd func() error) (id int, err error)
- func (c *Cron) AddMonthlyJob(name string, cmd func() error) (id int, err error)
- func (c *Cron) AddSecondlyJob(name string, cmd func() error) (id int, err error)
- func (c *Cron) AddWeeklyJob(name string, cmd func() error) (id int, err error)
- func (c *Cron) AddYearlyJob(name string, cmd func() error) (id int, err error)
- func (c *Cron) ClearJobs() error
- func (c *Cron) RemoveJob(id int) error
- type Debug
- type Env
- type Form
- type H
- type HTTPError
- type HandlerFunc
- type Middleware
- type Param
- type Query
- type Queue
- type ResponseWriter
- type RouterGroup
- func (g *RouterGroup) Any(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Delete(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Get(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Group(prefix string) *RouterGroup
- func (g *RouterGroup) Head(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Options(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Patch(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Post(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Put(path string, handler ...HandlerFunc) *RouterGroup
- func (g *RouterGroup) Static(relativePath string, root string, options ...StaticOptions)
- func (g *RouterGroup) StaticFS(relativePath string, fs http.FileSystem)
- func (g *RouterGroup) Use(middlewares ...HandlerFunc)
- func (g *RouterGroup) WebSocket(path string, handler WsHandlerFunc) *RouterGroup
- type Session
- type State
- type StaticOptions
- type User
- type WebSocketClient
- func (c *WebSocketClient) CreateJSONRPC() jsonrpc.Server[any]
- func (c *WebSocketClient) Disconnect()
- func (c *WebSocketClient) Write(typ int, msg []byte) error
- func (c *WebSocketClient) WriteBinary(msg []byte) error
- func (c *WebSocketClient) WriteBytes(msg []byte) error
- func (c *WebSocketClient) WriteJSON(msg interface{}) error
- func (c *WebSocketClient) WriteText(msg string) error
- type WsHandlerFunc
Constants ¶
const DebugEnv = "GO_ZOOX_DEBUG"
DebugEnv is the environment variable name for debug.
const HeaderContentType = "Content-Type"
HeaderContentType ...
Variables ¶
var DefaultGroupsFns = map[string]func(r *RouterGroup){}
DefaultGroupsFns ...
var DefaultMiddlewares = map[string]func(app *Application){}
DefaultMiddlewares is the default global middleware
var RequestIDHeader = "X-Request-Id"
RequestIDHeader is the name of the header that contains the request ID.
var Version = "1.3.17"
Version is the current version of the package.
Functions ¶
func DefaultGroup ¶ added in v1.0.16
func DefaultGroup(prefix string, fn func(r *RouterGroup))
DefaultGroup ...
func DefaultMiddleware ¶ added in v1.0.16
func DefaultMiddleware(name string, fn func(app *Application))
DefaultMiddleware ...
func GenerateRequestID ¶ added in v1.2.1
func GenerateRequestID() string
GenerateRequestID generates a unique request ID.
Types ¶
type Application ¶
type Application struct { *RouterGroup // SecretKey string LogLevel string // CacheConfig *typing.Config // Env *Env Logger *logger.Logger // contains filtered or unexported fields }
Application is the handler for all requests.
func (*Application) CreateJSONRPC ¶ added in v1.2.0
func (app *Application) CreateJSONRPC(path string) jsonrpc.Server[*Context]
CreateJSONRPC creates a new CreateJSONRPC handler.
func (*Application) Fallback ¶
func (app *Application) Fallback(h HandlerFunc)
Fallback is the default handler for all requests.
func (*Application) IsProd ¶ added in v1.1.0
func (app *Application) IsProd() bool
IsProd returns true if the app is in production mode.
func (*Application) NotFound ¶
func (app *Application) NotFound(h HandlerFunc)
NotFound defines the 404 handler, replaced of built in not found handler.
func (*Application) Run ¶
func (app *Application) Run(addr ...string) error
Run defines the method to start the server
func (*Application) ServeHTTP ¶
func (app *Application) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*Application) SetTemplates ¶
func (app *Application) SetTemplates(dir string, fns ...template.FuncMap)
SetTemplates set the template
type Body ¶ added in v1.3.12
type Body struct {
// contains filtered or unexported fields
}
Body ...
type Cache ¶ added in v1.0.24
type Cache struct {
// contains filtered or unexported fields
}
Cache ...
type Context ¶
type Context struct { // origin objects Writer ResponseWriter Request *http.Request // request Method string Path string // response StatusCode int // App *Application // Logger *logger.Logger // contains filtered or unexported fields }
Context is the request context
func (*Context) AcceptHTML ¶ added in v1.3.12
AcceptHTML returns true if the request accepts html.
func (*Context) AcceptJSON ¶ added in v1.0.19
AcceptJSON returns true if the request accepts json.
func (*Context) Authorization ¶ added in v1.3.16
Authorization returns the authorization header for auth.
func (*Context) BasicAuth ¶ added in v1.0.1
BasicAuth returns the user/password pair for Basic Authentication.
func (*Context) BearerToken ¶ added in v1.3.16
BearerToken returns the token for bearer authentication.
func (*Context) BindHeader ¶ added in v1.0.1
BindHeader binds the header into the given struct.
func (*Context) BindParams ¶ added in v1.0.1
BindParams binds the params into the given struct.
func (*Context) Data ¶ added in v1.2.19
Data writes some data into the body stream and updates the HTTP code. Align to gin framework.
func (*Context) Error ¶
Error writes the given error to the response. Use for system errors
- Internal server error
- Not found
func (*Context) Fail ¶
Fail writes the given error with code-message-result specification to the response.
func (*Context) FailWithError ¶ added in v1.1.0
FailWithError writes the given error with code-message-result specification to the response.
func (*Context) Files ¶ added in v1.0.1
func (ctx *Context) Files() map[string]*multipart.FileHeader
Files gets all files.
func (*Context) GetRawData ¶ added in v1.2.19
GetRawData returns stream data. Align to gin framework.
func (*Context) IP ¶ added in v1.0.4
IP gets the ip from X-Forwarded-For or X-Real-IP or RemoteAddr.
func (*Context) Next ¶
func (ctx *Context) Next()
Next runs the next handler in the middleware stack
func (*Context) Stream ¶ added in v1.0.1
func (ctx *Context) Stream() io.ReadCloser
Stream get the body stream.
func (*Context) Success ¶
func (ctx *Context) Success(result interface{})
Success writes the given data with code-message-result specification to the response.
type Cookie ¶ added in v1.0.5
type Cookie struct {
// contains filtered or unexported fields
}
Cookie is a middleware for handling cookie.
type Cron ¶ added in v1.3.3
type Cron struct {
// contains filtered or unexported fields
}
Cron ...
func (*Cron) AddDailyJob ¶ added in v1.3.3
AddDailyJob adds a schedule job run in every day.
func (*Cron) AddHourlyJob ¶ added in v1.3.3
AddHourlyJob adds a schedule job run in every hour.
func (*Cron) AddMinutelyJob ¶ added in v1.3.3
AddMinutelyJob adds a schedule job run in every minute.
func (*Cron) AddMonthlyJob ¶ added in v1.3.3
AddMonthlyJob adds a schedule job run in every month.
func (*Cron) AddSecondlyJob ¶ added in v1.3.3
AddSecondlyJob adds a schedule job run in every second.
func (*Cron) AddWeeklyJob ¶ added in v1.3.3
AddWeeklyJob adds a schedule job run in every week.
func (*Cron) AddYearlyJob ¶ added in v1.3.3
AddYearlyJob adds a schedule job run in every year.
type Debug ¶ added in v1.2.4
type Debug struct {
// contains filtered or unexported fields
}
Debug ...
type HandlerFunc ¶
type HandlerFunc func(ctx *Context)
HandlerFunc defines the request handler used by gee
func NotFound ¶
func NotFound() HandlerFunc
NotFound returns a HandlerFunc that replies with a 404 not found
func WrapH ¶
func WrapH(handler http.Handler) HandlerFunc
WrapH wraps a http.Handler to a HandlerFunc
type Middleware ¶ added in v1.0.20
type Middleware = HandlerFunc
Middleware defines the signature of the middleware function.
type Param ¶ added in v1.1.0
type Param struct {
// contains filtered or unexported fields
}
Param ...
type Query ¶ added in v1.1.0
type Query struct {
// contains filtered or unexported fields
}
Query ...
type Queue ¶ added in v1.3.3
type Queue struct {
// contains filtered or unexported fields
}
Queue is a simple job queue.
type ResponseWriter ¶ added in v1.0.12
type ResponseWriter interface { http.ResponseWriter http.Hijacker http.CloseNotifier http.Flusher // Status returns the HTTP response status code of the current request. Status() int // Size returns the number of bytes already written into the response http body. // See Written() Size() int // WriteString writes the string into the response body. WriteString(string) (int, error) // Written returns true if the response body was already written. Written() bool // WriteHeaderNow forces to write the http header (status code + headers). WriteHeaderNow() // Pusher get the http.Pusher for server push Pusher() http.Pusher // contains filtered or unexported methods }
ResponseWriter ...
type RouterGroup ¶
type RouterGroup struct {
// contains filtered or unexported fields
}
RouterGroup is a group of routes.
func (*RouterGroup) Any ¶ added in v1.0.3
func (g *RouterGroup) Any(path string, handler ...HandlerFunc) *RouterGroup
Any defines all request methods (anyMethods)
func (*RouterGroup) Delete ¶
func (g *RouterGroup) Delete(path string, handler ...HandlerFunc) *RouterGroup
Delete defines the method to add DELETE request
func (*RouterGroup) Get ¶
func (g *RouterGroup) Get(path string, handler ...HandlerFunc) *RouterGroup
Get defines the method to add GET request
func (*RouterGroup) Group ¶
func (g *RouterGroup) Group(prefix string) *RouterGroup
Group defines a new router group
func (*RouterGroup) Head ¶
func (g *RouterGroup) Head(path string, handler ...HandlerFunc) *RouterGroup
Head defines the method to add HEAD request
func (*RouterGroup) Options ¶ added in v1.0.3
func (g *RouterGroup) Options(path string, handler ...HandlerFunc) *RouterGroup
Options defines the method to add OPTIONS request
func (*RouterGroup) Patch ¶
func (g *RouterGroup) Patch(path string, handler ...HandlerFunc) *RouterGroup
Patch defines the method to add PATCH request
func (*RouterGroup) Post ¶
func (g *RouterGroup) Post(path string, handler ...HandlerFunc) *RouterGroup
Post defines the method to add POST request
func (*RouterGroup) Put ¶
func (g *RouterGroup) Put(path string, handler ...HandlerFunc) *RouterGroup
Put defines the method to add PUT request
func (*RouterGroup) Static ¶
func (g *RouterGroup) Static(relativePath string, root string, options ...StaticOptions)
Static defines the method to serve static files
func (*RouterGroup) StaticFS ¶ added in v1.0.15
func (g *RouterGroup) StaticFS(relativePath string, fs http.FileSystem)
StaticFS defines the method to serve static files
func (*RouterGroup) Use ¶
func (g *RouterGroup) Use(middlewares ...HandlerFunc)
Use adds a middleware to the group
func (*RouterGroup) WebSocket ¶ added in v1.0.28
func (g *RouterGroup) WebSocket(path string, handler WsHandlerFunc) *RouterGroup
WebSocket defines the method to add websocket route
type Session ¶ added in v1.0.14
type Session struct {
// contains filtered or unexported fields
}
Session is the http session based on cookie.
type State ¶ added in v1.1.0
type State struct {
// contains filtered or unexported fields
}
State is the state for request context.
type StaticOptions ¶
type StaticOptions struct { Gzip bool Md5 bool CacheControl string MaxAge time.Duration Index bool Suffix string }
StaticOptions is the options for static method
type User ¶ added in v1.1.0
type User struct {
// contains filtered or unexported fields
}
User is the user for request context.
type WebSocketClient ¶ added in v1.0.28
type WebSocketClient struct { OnConnect func() OnDisconnect func() OnMessage func(typ int, msg []byte) OnTextMessage func(msg []byte) OnBinaryMessage func(msg []byte) OnError func(err error) // contains filtered or unexported fields }
WebSocketClient ...
func (*WebSocketClient) CreateJSONRPC ¶ added in v1.2.7
func (c *WebSocketClient) CreateJSONRPC() jsonrpc.Server[any]
CreateJSONRPC ...
func (*WebSocketClient) Disconnect ¶ added in v1.0.28
func (c *WebSocketClient) Disconnect()
Disconnect ...
func (*WebSocketClient) Write ¶ added in v1.0.28
func (c *WebSocketClient) Write(typ int, msg []byte) error
Write ...
func (*WebSocketClient) WriteBinary ¶ added in v1.0.28
func (c *WebSocketClient) WriteBinary(msg []byte) error
WriteBinary ...
func (*WebSocketClient) WriteBytes ¶ added in v1.2.7
func (c *WebSocketClient) WriteBytes(msg []byte) error
WriteBytes ...
func (*WebSocketClient) WriteJSON ¶ added in v1.0.28
func (c *WebSocketClient) WriteJSON(msg interface{}) error
WriteJSON ...
func (*WebSocketClient) WriteText ¶ added in v1.0.28
func (c *WebSocketClient) WriteText(msg string) error
WriteText ...
type WsHandlerFunc ¶ added in v1.0.28
type WsHandlerFunc func(ctx *Context, client *WebSocketClient)
WsHandlerFunc defines the websocket handler used by gee