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) 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
AccessLevel defines role-based access control (required if CRUD implemented)
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) 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
DataValidator validates complete data before action (required if CRUD implemented)
type MiddlewareProvider ¶
MiddlewareProvider allows handlers to provide global HTTP middleware
type NamedHandler ¶
type NamedHandler interface {
HandlerName() string
}
NamedHandler provides the unique name for the entity (required if CRUD implemented)
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