contracts/routing.go
2023-04-12 16:56:55 +08:00

97 lines
2.5 KiB
Go

package contracts
import (
"net/http"
"github.com/go-chi/chi"
"github.com/gorilla/websocket"
)
type RouteCategory string
type RouteService string
type RouteCtx struct {
Name string
}
const (
RouteCategory_WS RouteCategory = "ws"
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_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_CONDITION_LAYOUT RouteService = "list-condition-layout"
RouteService_LIST_OPERATIONS_ACCESS RouteService = "list-operations-access"
)
func (k RouteCtx) String() string {
return k.Name
}
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) GlobalParams
GetResource() Resource
GetCategory() RouteCategory
GetService() RouteService
GetRoles() []string
MakeRequest(r *http.Request, params map[string]any) (*http.Request, 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
}