Documentation
¶
Index ¶
- func ActionToMethod(action byte) string
- func MethodToAction(method string) byte
- type BatchRequest
- type BatchResponse
- type Creator
- type CrudP
- func (cp *CrudP) ApplyMiddleware(handler http.Handler) http.Handler
- func (cp *CrudP) CallHandler(ctx context.Context, handlerID uint8, action byte, data ...any) (any, error)
- func (cp *CrudP) Execute(ctx context.Context, req *BatchRequest) (*BatchResponse, error)
- func (cp *CrudP) GetHandlerName(handlerID uint8) string
- func (cp *CrudP) RegisterHandler(handlers ...any) error
- func (cp *CrudP) RegisterRoutes(mux *http.ServeMux)
- func (cp *CrudP) SetLog(log func(...any))
- type DecodeFunc
- type Deleter
- type EncodeFunc
- type FieldValidator
- type HttpRouteProvider
- type MiddlewareProvider
- type NamedHandler
- type Packet
- type PacketResult
- type Reader
- type Updater
- type Validator
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 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 New ¶
func New(encode EncodeFunc, decode DecodeFunc) *CrudP
New creates a new CrudP instance with mandatory serialization functions
func (*CrudP) ApplyMiddleware ¶
ApplyMiddleware collects all middleware from handlers and wraps the provided handler
func (*CrudP) CallHandler ¶
func (cp *CrudP) CallHandler(ctx context.Context, handlerID uint8, action byte, data ...any) (any, error)
CallHandler searches and calls the handler directly by shared index
func (*CrudP) Execute ¶
func (cp *CrudP) Execute(ctx context.Context, req *BatchRequest) (*BatchResponse, error)
Execute processes a BatchRequest and returns a BatchResponse
func (*CrudP) GetHandlerName ¶
GetHandlerName returns the handler name by its ID
func (*CrudP) RegisterHandler ¶
RegisterHandler prepares the shared handler table
func (*CrudP) RegisterRoutes ¶
RegisterRoutes registers the default CRUD API endpoint and any custom routes from handlers
type DecodeFunc ¶
type EncodeFunc ¶
type FieldValidator ¶
FieldValidator validates individual fields for UI (optional)
type HttpRouteProvider ¶
HttpRouteProvider allows handlers to register custom HTTP routes
type MiddlewareProvider ¶
MiddlewareProvider allows handlers to provide global HTTP middleware
type NamedHandler ¶
type NamedHandler interface {
HandlerName() string
}
NamedHandler allows override of automatic name (optional) If not implemented, reflection is used: TypeName -> snake_case
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