Documentation
¶
Index ¶
- Variables
- func AddGuard(name string, guard gin.HandlerFunc)
- func BuildHandler(http HTTP, path Path) gin.HandlerFunc
- func BuildRouteTable()
- func FindHandler(method, path string) (*API, *Path, gin.HandlerFunc, map[string]string, error)
- func IsAllowed(c *gin.Context, allowsMap map[string]bool) bool
- func ProcessGuard(name string, cors ...gin.HandlerFunc) gin.HandlerFunc
- func ReloadAPIs(root string) error
- func SetGuards(guards map[string]gin.HandlerFunc)
- func SetRoutes(router *gin.Engine, path string, allows ...string)
- type API
- type HTTP
- type Out
- type Path
- type Redirect
- type RouteEntry
- type RouteTable
Constants ¶
This section is empty.
Variables ¶
var APIs = map[string]*API{}
APIs is the loaded API list
var HTTPGuards = map[string]gin.HandlerFunc{}
HTTPGuards 支持的中间件
Functions ¶
func BuildHandler ¶ added in v1.0.0
func BuildHandler(http HTTP, path Path) gin.HandlerFunc
BuildHandler builds a gin.HandlerFunc for the given HTTP and Path configuration This is the public API for building handlers dynamically
func BuildRouteTable ¶ added in v1.0.0
func BuildRouteTable()
BuildRouteTable builds the route table from loaded APIs Should be called after loading APIs and before using FindHandler
func FindHandler ¶ added in v1.0.0
FindHandler finds a handler by method and path from the route table Returns the API, Path, Handler, extracted parameters, and error
func ProcessGuard ¶
func ProcessGuard(name string, cors ...gin.HandlerFunc) gin.HandlerFunc
ProcessGuard guard process
func ReloadAPIs ¶ added in v1.0.0
ReloadAPIs reloads all API definitions from the specified directory This function is thread-safe and performs atomic replacement of both APIs and the route table
Types ¶
type API ¶
API 数据接口
func LoadSource ¶ added in v1.0.0
LoadSource parses API source data, registers it to the global APIs map, and returns the *API
type HTTP ¶
type HTTP struct {
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
Group string `json:"group,omitempty"`
Guard string `json:"guard,omitempty"`
Paths []Path `json:"paths,omitempty"`
}
HTTP http 协议服务
type Out ¶
type Out struct {
Status int `json:"status"`
Type string `json:"type,omitempty"`
Body interface{} `json:"body,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Redirect *Redirect `json:"redirect,omitempty"`
}
Out http 输出
type Path ¶
type Path struct {
Label string `json:"label,omitempty"`
Description string `json:"description,omitempty"`
Path string `json:"path"`
Method string `json:"method"`
Process string `json:"process"`
Guard string `json:"guard,omitempty"`
In []interface{} `json:"in,omitempty"`
Out Out `json:"out,omitempty"`
ProcessHandler bool `json:"processHandler,omitempty"`
}
Path HTTP Path
type Redirect ¶
type Redirect struct {
Code int `json:"code,omitempty"`
Location string `json:"location,omitempty"`
}
Redirect out redirect
type RouteEntry ¶ added in v1.0.0
type RouteEntry struct {
Pattern string // Original route pattern, e.g., /user/:id
Regex *regexp.Regexp // Compiled regex for matching
Params []string // Parameter names, e.g., ["id"]
API *API // Reference to the API definition
Path *Path // Reference to the Path definition
}
RouteEntry represents a single route entry
type RouteTable ¶ added in v1.0.0
type RouteTable struct {
// contains filtered or unexported fields
}
RouteTable is a thread-safe route table for dynamic route lookup