Documentation
¶
Index ¶
- func ActionToMethod(action byte) string
- func MethodToAction(method string) byte
- type AccessDeniedHandler
- type AccessLevel
- type BatchRequest
- type BatchResponse
- type Creator
- type CrudP
- func (cp *CrudP) ApplyMiddleware(handler http.Handler) http.Handler
- func (cp *CrudP) CallHandler(handlerID uint8, action byte, data ...any) (any, error)
- func (cp *CrudP) Execute(req *BatchRequest, inject ...any) (*BatchResponse, error)
- func (cp *CrudP) GetHandlerName(handlerID uint8) string
- func (cp *CrudP) IsDevMode() bool
- func (cp *CrudP) RegisterHandlers(handlers ...any) error
- func (cp *CrudP) RegisterRoutes(mux *http.ServeMux)
- func (cp *CrudP) SetAccessCheck(fn func(resource string, action byte, data ...any) bool)
- func (cp *CrudP) SetAccessDeniedHandler(fn AccessDeniedHandler)
- func (cp *CrudP) SetCodecs(encode, decode func(input any, output any) error)
- func (cp *CrudP) SetDevMode(enabled bool)
- func (cp *CrudP) SetLog(log func(...any))
- func (cp *CrudP) SetUserRoles(fn func(data ...any) []byte)
- type DataValidator
- type Deleter
- type MiddlewareProvider
- type NamedHandler
- type Packet
- type PacketResult
- type Reader
- type Request
- type Response
- type Updater
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ActionToMethod ¶
ActionToMethod converts CRUD action byte to HTTP method
func MethodToAction ¶
MethodToAction converts HTTP method to CRUD action byte
Types ¶
type AccessDeniedHandler ¶ added in v0.2.0
type AccessDeniedHandler func(handler string, action byte, userRoles []byte, allowedRoles []byte, errMsg string)
AccessDeniedHandler defines the callback for failed access attempts
type AccessLevel ¶ added in v0.2.0
type BatchRequest ¶
type BatchRequest struct {
Packets []Packet `json:"packets"`
}
BatchRequest is what is sent in the POST /sync
type BatchResponse ¶
type BatchResponse struct {
Results []PacketResult `json:"results"`
}
BatchResponse is what is received by SSE or as HTTP response
type Creator ¶
Separate CRUD interfaces - handlers implement only what they need Return `any` which internally can be slice for multiple items
type CrudP ¶
type CrudP struct {
// contains filtered or unexported fields
}
CrudP handles automatic handler processing
func (*CrudP) ApplyMiddleware ¶
ApplyMiddleware collects all middleware from handlers and wraps the provided handler
func (*CrudP) CallHandler ¶
CallHandler searches and calls the handler directly by shared index
func (*CrudP) Execute ¶
func (cp *CrudP) Execute(req *BatchRequest, inject ...any) (*BatchResponse, error)
Execute processes a BatchRequest and returns a BatchResponse inject contains values to prepend to handler data (e.g., context, http.Request)
func (*CrudP) GetHandlerName ¶
GetHandlerName returns the handler name by its ID
func (*CrudP) RegisterHandlers ¶ added in v0.1.0
RegisterHandlers prepares the shared handler table
func (*CrudP) RegisterRoutes ¶
func (*CrudP) SetAccessCheck ¶ added in v0.2.25
SetAccessCheck configures an external access check function. When set, AllowedRoles() interface is NOT required on handlers. The function receives the handler's resource name, the action byte ('c','r','u','d'), and the raw request data (same variadic as SetUserRoles closure). Must be called before RegisterHandlers(). Mutually exclusive with SetUserRoles — use one or the other.
func (*CrudP) SetAccessDeniedHandler ¶ added in v0.2.0
func (cp *CrudP) SetAccessDeniedHandler(fn AccessDeniedHandler)
SetAccessDeniedHandler configures a callback for failed access attempts
func (*CrudP) SetDevMode ¶ added in v0.2.0
SetDevMode enables or disables development mode (bypasses access checks)
func (*CrudP) SetUserRoles ¶ added in v0.2.1
SetUserRoles configures the current user's roles extractor. Access checks are enabled when RegisterRoutes is called on the server.
type DataValidator ¶ added in v0.1.0
type MiddlewareProvider ¶
MiddlewareProvider allows handlers to provide global HTTP middleware
type NamedHandler ¶
type NamedHandler interface {
HandlerName() string
}
type Packet ¶
type Packet struct {
Action byte `json:"action"`
HandlerID uint8 `json:"handler_id"`
ReqID string `json:"req_id"`
Data [][]byte `json:"data"`
}
Packet represents both requests and responses of the protocol
type PacketResult ¶
type Request ¶ added in v0.0.20
Request represents a single operation request for automatic endpoints