contracts/routing.go

140 lines
3.9 KiB
Go

package contracts
import (
"net/http"
"github.com/go-chi/chi/v5"
"github.com/gorilla/websocket"
)
type RouteMethod string
type RouteCategory string
type RouteService string
type RouteParamType string
type RouteParamCategory string
type RouteCtx struct {
Name string
}
const (
RouteMethod_GET RouteMethod = "GET"
RouteMethod_POST RouteMethod = "POST"
RouteMethod_PUT RouteMethod = "PUT"
RouteMethod_DELETE RouteMethod = "DELETE"
)
const (
RouteCategory_WS RouteCategory = "ws"
RouteCategory_GRPC RouteCategory = "grpc"
RouteCategory_FUNC RouteCategory = "func"
RouteCategory_SHOW RouteCategory = "show"
RouteCategory_QUERY RouteCategory = "query"
RouteCategory_STORE RouteCategory = "store"
RouteCategory_DESTROY RouteCategory = "destroy"
RouteCategory_STRUCTURE RouteCategory = "structure"
)
const (
RouteService_API RouteService = "api"
RouteService_FSM RouteService = "fsm"
RouteService_LIST RouteService = "list"
RouteService_XLSX RouteService = "xlsx"
RouteService_IMPORT RouteService = "import"
RouteService_PRINT RouteService = "print"
RouteService_LAYOUT RouteService = "layout"
RouteService_GRID_LAYOUT RouteService = "grid-layout"
RouteService_GRID_LAYOUT_FORM RouteService = "grid-layout-form"
RouteService_ECHART RouteService = "echart"
RouteService_APPROVAL RouteService = "approval"
RouteService_SELECTOR RouteService = "selector"
RouteService_LIST_DETAIL RouteService = "list-detail"
RouteService_LIST_DATA_STORE RouteService = "list-data-store"
RouteService_LIST_GRID_LAYOUT RouteService = "list-grid-layout"
RouteService_LIST_CONDITION_LAYOUT RouteService = "list-condition-layout"
RouteService_LIST_OPERATIONS_ACCESS RouteService = "list-operations-access"
)
const (
RouteParam_STRING RouteParamType = "string"
RouteParam_BOOL RouteParamType = "bool"
RouteParam_NUMBER RouteParamType = "number"
RouteParam_INTEGER RouteParamType = "integer"
RouteParam_FLOAT RouteParamType = "float"
RouteParam_JSON RouteParamType = "json"
RouteParam_ARRAY RouteParamType = "array"
RouteParam_ANY RouteParamType = "any"
)
const (
RouteParamCategory_ROUTER RouteParamCategory = "router"
RouteParamCategory_HEADER RouteParamCategory = "header"
RouteParamCategory_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
}
type WsClientGroup string
type WsClientID uint
// type WsClient struct {
// User
// Group WsClientGroup
// Socket *websocket.Conn
// }
type WsClient interface {
User
Socket() *websocket.Conn
WsClientID() WsClientID
WsClientGroup() WsClientGroup
WsClientManage() WsClientManage
Lock()
Unlock()
}
type WsClientManage interface {
Register(WsClient) bool
Unregister(WsClient)
GetClients(func(WsClient) bool) []WsClient
}
type WsChannelManage interface {
Channel(string) WsClientManage
}