Documentation ¶
Index ¶
- Constants
- Variables
- func Corn(pattern string, handler func(), initExec bool)
- func DELETE[T any](path string, handler func(ctx *Context[T]), opts ...*ApiOpts)
- func Env(key string) string
- func GET[T any](path string, handler func(ctx *Context[T]), opts ...*ApiOpts)
- func InitJob(handler func(), after bool)
- func Middleware(handler func(ctx *Context[struct{}]), matchPaths []string, skipPaths []string)
- func NewMemMigrate(m ...any)
- func NewMigrate(m ...any)
- func POST[T any](path string, handler func(ctx *Context[T]), opts ...*ApiOpts)
- func PUT[T any](path string, handler func(ctx *Context[T]), opts ...*ApiOpts)
- func WS[T any](path string, handler func(ctx *Context[T], ws *websocket.Conn))
- type ApiHandler
- type ApiInfo
- type ApiOpts
- type CacheOpt
- type Context
- func (c *Context[T]) Agent() string
- func (c *Context[T]) Authorization() string
- func (c *Context[T]) BearerToken() string
- func (c *Context[T]) Err(message string)
- func (c *Context[T]) Forbidden(message string)
- func (c *Context[T]) IP() string
- func (c *Context[T]) InternalServerError(message string)
- func (c *Context[T]) Locale() string
- func (c *Context[T]) LogDebug(msg ...any)
- func (c *Context[T]) LogErr(msg ...any)
- func (c *Context[T]) LogInfo(msg ...any)
- func (c *Context[T]) OK(data any, page ...*gorm.Pagination)
- func (c *Context[T]) OKDownload(bytes []byte, filename ...string)
- func (c *Context[T]) OKFile(bytes []byte, filename ...string)
- func (c *Context[T]) Page() *gorm.Pagination
- func (c *Context[T]) Sort() *gorm.Sorting
- func (c *Context[T]) TraceID() string
- func (c *Context[T]) Unauthorized(message string)
- type CornHandler
- type InitJobHandler
- type MiddlewareHandler
- type RateLimitOpt
- type Response
- type TypescriptOpt
- type WsHandler
Constants ¶
const ( HEADER_AUTHORIZATION = "Authorization" HEADER_X_LOCALE = "X-Locale" )
const ( DB_TYPE_MYSQL = "mysql" DB_TYPE_PGSQL = "postgres" DB_TYPE_MEM = "memory" )
Variables ¶
var ApiService = new(apiService)
var Engine = newEngine()
Engine is the framework's instance. It is supposed to be one per application.
var FileService = new(fileService)
var ModelService = new(modelService)
Functions ¶
func Env ¶
Env returns the environment variable value by the key. The key will be stored in the engine.
func Middleware ¶
func NewMemMigrate ¶ added in v1.0.1
func NewMemMigrate(m ...any)
func NewMigrate ¶ added in v1.0.1
func NewMigrate(m ...any)
Types ¶
type ApiHandler ¶
type ApiHandler struct { Handler gin.HandlerFunc `json:"-"` Method string `json:"method"` Path string `json:"path"` Opts *ApiOpts `json:"opts"` }
type ApiOpts ¶
type ApiOpts struct { RateLimit *RateLimitOpt `json:"rate_limit"` Cache *CacheOpt `json:"cache"` Typescript *TypescriptOpt `json:"typescript"` }
type Context ¶
type Context[T any] struct { Engine *engine GinCtx *gin.Context TraceId string Request *T Response *Response // contains filtered or unexported fields }
func (*Context[T]) Authorization ¶
Authorization returns the authorization from the request header.
func (*Context[T]) BearerToken ¶
BearerToken returns the bearer token from the request header.
func (*Context[T]) Forbidden ¶
Forbidden is a helper function to respond with a forbidden status code (403).
func (*Context[T]) InternalServerError ¶
InternalServerError is a helper function to respond with an internal server error status code (500).
func (*Context[T]) OK ¶
func (c *Context[T]) OK(data any, page ...*gorm.Pagination)
OK returns a successful response.
func (*Context[T]) OKDownload ¶
OKDownload is a helper function to respond with a 200 status code and file.
func (*Context[T]) Page ¶
func (c *Context[T]) Page() *gorm.Pagination
Page returns the pagination object from the request.
func (*Context[T]) Unauthorized ¶
Unauthorized is a helper function to respond with an unauthorized status code (401).
type CornHandler ¶
type InitJobHandler ¶
type InitJobHandler struct { Handler func() `json:"-"` After bool `json:"after"` }
type MiddlewareHandler ¶
type MiddlewareHandler struct { Handler gin.HandlerFunc `json:"-"` MatchPaths []string `json:"match_paths"` SkipPaths []string `json:"exclude"` }
type RateLimitOpt ¶
type TypescriptOpt ¶
type WsHandler ¶
type WsHandler struct { Handler gin.HandlerFunc `json:"-"` Path string `json:"path"` }