2024-05-08 21:35:26 +08:00
|
|
|
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 (
|
2024-05-09 11:35:23 +08:00
|
|
|
ReqString RouteParamType = "string"
|
|
|
|
ReqBool RouteParamType = "bool"
|
|
|
|
ReqNumber RouteParamType = "number"
|
|
|
|
ReqInteger RouteParamType = "integer"
|
|
|
|
ReqFloat RouteParamType = "float"
|
|
|
|
ReqJson RouteParamType = "json"
|
|
|
|
ReqArray RouteParamType = "array"
|
|
|
|
ReqAny RouteParamType = "any"
|
2024-05-08 21:35:26 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|