110 lines
2.8 KiB
Go
110 lines
2.8 KiB
Go
|
package req
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/go-chi/chi/v5"
|
||
|
)
|
||
|
|
||
|
type RouteMethod string
|
||
|
type RouteCategory string
|
||
|
type RouteService string
|
||
|
type RouteParamType string
|
||
|
type RouteParamCategory string
|
||
|
|
||
|
type RouteCtx struct {
|
||
|
Name string
|
||
|
}
|
||
|
|
||
|
const (
|
||
|
GET RouteMethod = "GET"
|
||
|
POST RouteMethod = "POST"
|
||
|
PUT RouteMethod = "PUT"
|
||
|
DELETE RouteMethod = "DELETE"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
WS RouteCategory = "ws"
|
||
|
GRPC RouteCategory = "grpc"
|
||
|
FUNC RouteCategory = "func"
|
||
|
SHOW RouteCategory = "show"
|
||
|
QUERY RouteCategory = "query"
|
||
|
STORE RouteCategory = "store"
|
||
|
DESTROY RouteCategory = "destroy"
|
||
|
STRUCTURE RouteCategory = "structure"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
API RouteService = "api"
|
||
|
FSM RouteService = "fsm"
|
||
|
LIST RouteService = "list"
|
||
|
XLSX RouteService = "xlsx"
|
||
|
IMPORT RouteService = "import"
|
||
|
PRINT RouteService = "print"
|
||
|
LAYOUT RouteService = "layout"
|
||
|
GRID_LAYOUT RouteService = "grid-layout"
|
||
|
GRID_LAYOUT_FORM RouteService = "grid-layout-form"
|
||
|
ECHART RouteService = "echart"
|
||
|
APPROVAL RouteService = "approval"
|
||
|
SELECTOR RouteService = "selector"
|
||
|
LIST_DETAIL RouteService = "list-detail"
|
||
|
LIST_DATA_STORE RouteService = "list-data-store"
|
||
|
LIST_GRID_LAYOUT RouteService = "list-grid-layout"
|
||
|
LIST_CONDITION_LAYOUT RouteService = "list-condition-layout"
|
||
|
LIST_OPERATIONS_ACCESS RouteService = "list-operations-access"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
STRING RouteParamType = "string"
|
||
|
BOOL RouteParamType = "bool"
|
||
|
NUMBER RouteParamType = "number"
|
||
|
INTEGER RouteParamType = "integer"
|
||
|
FLOAT RouteParamType = "float"
|
||
|
JSON RouteParamType = "json"
|
||
|
ARRAY RouteParamType = "array"
|
||
|
ANY RouteParamType = "any"
|
||
|
)
|
||
|
|
||
|
const (
|
||
|
ROUTER RouteParamCategory = "router"
|
||
|
HEADER RouteParamCategory = "header"
|
||
|
PARAM RouteParamCategory = "param"
|
||
|
)
|
||
|
|
||
|
func (k RouteCtx) String() string {
|
||
|
return k.Name
|
||
|
}
|
||
|
|
||
|
type RouteMiddleware interface {
|
||
|
HttpMiddleware(r Route) func(next http.Handler) http.Handler
|
||
|
}
|
||
|
|
||
|
type Router interface {
|
||
|
Call(r *http.Request, code string, params map[string]any, category ...RouteCategory) (HttpResponse, error)
|
||
|
Get(uuid string, category ...RouteCategory) (Route, bool)
|
||
|
Register(cr chi.Router)
|
||
|
RefreshRoutes() error
|
||
|
}
|
||
|
|
||
|
type Route interface {
|
||
|
GetUuid() string
|
||
|
GetCode() string
|
||
|
GetPrimaryKey() string
|
||
|
GetUri() string
|
||
|
GetUris() []string
|
||
|
GetParamValues(*http.Request, ...RouteParam) (GlobalParams, error)
|
||
|
GetResource() Resource
|
||
|
GetCategory() RouteCategory
|
||
|
GetService() RouteService
|
||
|
GetRoles() []string
|
||
|
MakeRequest(r *http.Request, params map[string]any) (*http.Request, error)
|
||
|
}
|
||
|
|
||
|
type RouteParam interface {
|
||
|
GetCode() string
|
||
|
GetDataType() RouteParamType
|
||
|
GetCategory() RouteParamCategory
|
||
|
IsRequired() bool
|
||
|
InjectRequestToGlobalParams(*http.Request, GlobalParams) error
|
||
|
}
|