Documentation ¶
Overview ¶
Package KSbus is a minimalistic event bus demonstration on how useful is to design event based systems using Golang, allowing you to synchronise your backends and frontends
What is included in this package ? ¶
This package use [Kmux] wich is the same router as Korm
KSbus can be used between your go servers, and between your servers and client using the built in JS library ¶
Index ¶
- func GenerateRandomBytes(n int) ([]byte, error)
- func GenerateRandomString(s int) string
- func GenerateUUID() string
- func RestartSelf() error
- func RetryEvery(t time.Duration, function func() error, maxRetry ...int)
- func RunEvery(t time.Duration, fn func() bool)
- type Bus
- func (b *Bus) Publish(topic string, data map[string]any)
- func (b *Bus) PublishToID(id string, data map[string]any)
- func (b *Bus) PublishToIDWaitRecv(id string, data map[string]any, onRecv func(data map[string]any), ...) error
- func (b *Bus) PublishWaitRecv(topic string, data map[string]any, onRecv func(data map[string]any), ...) error
- func (b *Bus) RemoveTopic(topic string)
- func (b *Bus) Subscribe(topic string, fn func(data map[string]any, unsub Unsub), ...) Unsub
- func (b *Bus) Unsubscribe(topic string)
- type Client
- func (client *Client) Close() error
- func (client *Client) Publish(topic string, data map[string]any)
- func (client *Client) PublishToID(id string, data map[string]any)
- func (client *Client) PublishToIDWaitRecv(id string, data map[string]any, onRecv func(data map[string]any), ...)
- func (client *Client) PublishToServer(addr string, data map[string]any, secure ...bool)
- func (client *Client) PublishWaitRecv(topic string, data map[string]any, onRecv func(data map[string]any), ...)
- func (client *Client) RemoveTopic(topic string)
- func (client *Client) Run()
- func (client *Client) Subscribe(topic string, handler func(data map[string]any, unsub Unsub)) Unsub
- func (client *Client) Unsubscribe(topic string)
- type ClientConnectOptions
- type Server
- func (server *Server) AllTopics() []string
- func (s *Server) GetSubscribers(topic string) []Subscriber
- func (s *Server) OnDataWs(...)
- func (s *Server) OnId(fn func(data map[string]any))
- func (s *Server) OnServerData(fn func(data any, conn *ws.Conn))
- func (s *Server) OnWsClose(fn func(connID string))
- func (srv *Server) Publish(topic string, data map[string]any)
- func (s *Server) PublishToID(id string, data map[string]any)
- func (s *Server) PublishToIDWaitRecv(id string, data map[string]any, onRecv func(data map[string]any), ...)
- func (s *Server) PublishToServer(addr string, data map[string]any, secure ...bool) error
- func (s *Server) PublishWaitRecv(topic string, data map[string]any, onRecv func(data map[string]any), ...)
- func (s *Server) RemoveTopic(topic string)
- func (s *Server) Run()
- func (s *Server) RunAutoTLS(subDomains ...string)
- func (s *Server) RunTLS(cert string, certKey string)
- func (s *Server) Subscribe(topic string, fn func(data map[string]any, unsub Unsub)) (unsub Unsub)
- func (s *Server) Unsubscribe(topic string)
- func (s *Server) WithMetrics(httpHandler http.Handler, path ...string)
- func (s *Server) WithPprof(path ...string)
- type ServerOpts
- type Subscriber
- type Unsub
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateRandomString ¶
func GenerateUUID ¶ added in v1.1.8
func GenerateUUID() string
func RestartSelf ¶ added in v0.9.4
func RestartSelf() error
Types ¶
type Bus ¶
type Bus struct {
// contains filtered or unexported fields
}
Bus type handle all subscriptions, websockets and channels
func (*Bus) PublishToIDWaitRecv ¶ added in v1.2.5
func (*Bus) PublishWaitRecv ¶ added in v0.9.7
func (*Bus) RemoveTopic ¶
func (*Bus) Unsubscribe ¶
type Client ¶
type Client struct { Id string ServerAddr string RestartEvery time.Duration Conn *ws.Conn Autorestart bool Done chan struct{} // contains filtered or unexported fields }
func NewClient ¶
func NewClient(opts ClientConnectOptions) (*Client, error)
func (*Client) PublishToID ¶ added in v1.1.8
func (*Client) PublishToIDWaitRecv ¶ added in v1.2.0
func (*Client) PublishToServer ¶ added in v1.2.0
func (*Client) PublishWaitRecv ¶ added in v1.2.0
func (*Client) RemoveTopic ¶
func (*Client) Unsubscribe ¶
type ClientConnectOptions ¶ added in v1.1.8
type ClientConnectOptions struct { Id string Address string Secure bool Path string // default ksbus.ServerPath Autorestart bool RestartEvery time.Duration OnDataWs func(data map[string]any, conn *ws.Conn) error OnId func(data map[string]any, unsub Unsub) // used when client bus receive data on his ID 'client.Id' }
type Server ¶
type Server struct { ID string Address string Path string Bus *Bus App *ksmux.Router // contains filtered or unexported fields }
func NewServer ¶
func NewServer(options ...ServerOpts) *Server
func (*Server) GetSubscribers ¶ added in v1.1.8
func (s *Server) GetSubscribers(topic string) []Subscriber
func (*Server) OnServerData ¶ added in v1.2.3
func (*Server) PublishToID ¶ added in v1.1.8
func (*Server) PublishToIDWaitRecv ¶ added in v1.2.0
func (*Server) PublishToServer ¶ added in v1.2.0
func (*Server) PublishWaitRecv ¶ added in v0.9.7
func (*Server) RemoveTopic ¶
func (*Server) RunAutoTLS ¶
func (*Server) Unsubscribe ¶
func (*Server) WithMetrics ¶ added in v1.0.2
type ServerOpts ¶ added in v1.3.3
type ServerOpts struct { ID string Address string Path string BusMidws []func(ksmux.Handler) ksmux.Handler OnWsClose func(connID string) OnDataWS func(data map[string]any, conn *ws.Conn, originalRequest *http.Request) error OnServerData func(data any, conn *ws.Conn) OnId func(data map[string]any) OnUpgradeWs func(r *http.Request) bool WithOtherRouter *ksmux.Router WithOtherBus *Bus }
func NewDefaultServerOptions ¶ added in v1.3.3
func NewDefaultServerOptions() ServerOpts
type Subscriber ¶ added in v1.2.6
type Subscriber struct { Id string Topic string Ch chan map[string]any Conn *ws.Conn // contains filtered or unexported fields }
func (Subscriber) Unsubscribe ¶ added in v1.2.6
func (subs Subscriber) Unsubscribe()
Click to show internal directories.
Click to hide internal directories.