Documentation ¶
Index ¶
- type Client
- type ClientRequestOpts
- type Context
- type HandlerFunc
- type Meta
- type MiddlewareFunc
- type RBACContext
- type Request
- type Response
- type ResponseToClient
- type Router
- func (r *Router) Dispatch(topic string, ctx *Context)
- func (r *Router) DispatchEvent(topic string, ctx *Context)
- func (r *Router) Handle(topic string, handler HandlerFunc)
- func (r *Router) HandleEvent(topic string, handler HandlerFunc)
- func (r *Router) Run(natsURL string) error
- func (r *Router) WithPermission(rbac RBACContext) *Router
- func (r *Router) WithResource(resource string) *Router
- type SystemMessage
- type SystemResponse
- type SystemResponseOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Request ¶
func (c *Client) Request(topic string, opts ...ClientRequestOpts) (*ResponseToClient, error)
type ClientRequestOpts ¶
type ClientRequestOpts func(*SystemMessage)
func WithArg ¶
func WithArg(args string) ClientRequestOpts
func WithPayloadClient ¶
func WithPayloadClient(payload interface{}) ClientRequestOpts
func WithPayloadClientRaw ¶
func WithPayloadClientRaw(payload interface{}) ClientRequestOpts
func WithQueryClient ¶
func WithQueryClient(uv url.Values) ClientRequestOpts
func WithTokenClient ¶
func WithTokenClient(token string) ClientRequestOpts
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
func (*Context) Error ¶
func (ctx *Context) Error(opts ...SystemResponseOption)
Error is a helper function to reply with a SystemResponse and error
type MiddlewareFunc ¶
type MiddlewareFunc func(next HandlerFunc) HandlerFunc
func RBAC ¶
func RBAC(action string) MiddlewareFunc
type RBACContext ¶
type RBACContext interface { WithToken(string) RBACContext WithResource(string) RBACContext Can(action string) bool }
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func (*Request) GetPayload ¶
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response struct
func (*Response) Notify ¶
func (r *Response) Notify(topic string, payload interface{}, opts ...SystemResponseOption) error
Notify sends a notification to a topic with payload and options
func (*Response) Reply ¶
func (r *Response) Reply(payload interface{}, opts ...SystemResponseOption) error
Reply sends a reply to the request with payload and options
type ResponseToClient ¶
type ResponseToClient struct { Data responseToClient `json:"data,omitempty"` Code int `json:"code"` Message string `json:"message"` }
func (*ResponseToClient) CopyTo ¶
func (r *ResponseToClient) CopyTo(to *json.RawMessage) error
func (*ResponseToClient) To ¶
func (r *ResponseToClient) To(to interface{}) error
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router struct
func (*Router) DispatchEvent ¶
Dispatch dispatches the message to the right handler
func (*Router) Handle ¶
func (r *Router) Handle(topic string, handler HandlerFunc)
Handle registers a new route with a handler
func (*Router) HandleEvent ¶
func (r *Router) HandleEvent(topic string, handler HandlerFunc)
func (*Router) WithPermission ¶
func (r *Router) WithPermission(rbac RBACContext) *Router
func (*Router) WithResource ¶
type SystemMessage ¶
type SystemMessage struct { Meta *Meta `json:"meta"` Payload string `json:"payload"` Query url.Values `json:"query"` Arg string `json:"arg"` }
func (*SystemMessage) Marshal ¶
func (m *SystemMessage) Marshal() ([]byte, error)
func (*SystemMessage) Unmarshal ¶
func (m *SystemMessage) Unmarshal(data []byte) error
type SystemResponse ¶
type SystemResponse struct { Code int `json:"code"` Message string `json:"message"` Type string `json:"type,omitempty"` SysMsg *SystemMessage `json:"data,omitempty"` }
SystemMessage is the data field of SystemResponse
func NewSystemResponse ¶
func NewSystemResponse(code int, message string) *SystemResponse
SystemMessage is the data field of SystemResponse
func (*SystemResponse) ToJSON ¶
func (e *SystemResponse) ToJSON() string
Convert the struct to JSON, handle errors as needed
type SystemResponseOption ¶
type SystemResponseOption func(*SystemResponse)
SystemResponseOption is a function that modifies a SystemResponse
func WithCode ¶
func WithCode(code int) SystemResponseOption
WithCode is a helper function to reply with a SystemResponse and specific code
func WithError ¶
func WithError(code int, message string) SystemResponseOption
WithError is a helper function to reply with a SystemResponse and error
func WithMessage ¶
func WithMessage(msg string) SystemResponseOption
WithMessage is a helper function to reply with a SystemResponse and specific message