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 ( ReqString RouteParamType = "string" ReqBool RouteParamType = "bool" ReqNumber RouteParamType = "number" ReqInteger RouteParamType = "integer" ReqFloat RouteParamType = "float" ReqJson RouteParamType = "json" ReqArray RouteParamType = "array" ReqAny 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, opts ...RouteMatchOption) (HttpResponse, error) Get(uuid string, opts ...RouteMatchOption) (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 } type RouteMatchOption func(opts *RouteMatches) type RouteMatches struct { categories []RouteCategory services []RouteService } func (this RouteMatches) RouteCategories() []RouteCategory { return this.categories } func (this RouteMatches) RouteServices() []RouteService { return this.services } func RouteMatch[T RouteCategory | RouteService](v T) RouteMatchOption { return func(opt *RouteMatches) { switch value := any(v).(type) { case RouteCategory: opt.categories = append(opt.categories, value) case RouteService: opt.services = append(opt.services, value) } } }