Documentation
¶
Overview ¶
Index ¶
- Constants
- func BadRequest(w http.ResponseWriter, msg string)
- func BearerAuth(r *http.Request) (string, error)
- func ErrorStatusCode(code string) int
- func Forbidden(w http.ResponseWriter, msg string)
- func FromErrorStatusCode(code int) string
- func InternalServerError(w http.ResponseWriter, msg string)
- func InvalidSession(w http.ResponseWriter)
- func NotAuthenticaded(w http.ResponseWriter)
- func OK(w http.ResponseWriter, msg string)
- func ReadBool(qs url.Values, key string) bool
- func ReadCSV(qs url.Values, key string, defaulValue []string) []string
- func ReadInt(qs url.Values, key string, defaultValue int, v *validator.Validator) int
- func ReadString(qs url.Values, key string, defaulValue string) string
- func ReadTime(qs url.Values, key string, defaulValue time.Time) time.Time
- func ReadTimeString(qs url.Values, key string, defaulValue string) string
- func ReadURLParam(r *http.Request, key string) (string, error)
- func ReadUUIDParam(r *http.Request, key string) (uuid.UUID, error)
- func TooManyRequestsError(w http.ResponseWriter, msg string)
- func Unauthorized(w http.ResponseWriter, msg string)
- func ValidateRecipient(v *validator.Validator, recipient *echosight.Recipient)
- type Client
- type ClientList
- type Event
- type EventHandler
- type HandlerFunc
- type NewMessageEvent
- type RateLimiter
- type Response
- type ResponseStatus
- type SendMessageEvent
- type Server
- type ServerOpts
- type W
- type WebSocketManager
Constants ¶
View Source
const ( EventSendMessage = "send_message" EventNewMessage = "new_message" )
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
func BadRequest(w http.ResponseWriter, msg string)
func ErrorStatusCode ¶
ErrorStatusCode returns the associated HTTP status code
func Forbidden ¶
func Forbidden(w http.ResponseWriter, msg string)
func FromErrorStatusCode ¶
FromErrorStatusCode returns the associated code for an HTTP status code.
func InternalServerError ¶
func InternalServerError(w http.ResponseWriter, msg string)
func InvalidSession ¶
func InvalidSession(w http.ResponseWriter)
func NotAuthenticaded ¶
func NotAuthenticaded(w http.ResponseWriter)
func OK ¶
func OK(w http.ResponseWriter, msg string)
func ReadBool ¶
ReadBoolParam reads the key from the url query and returns true if the param is equal 'true' otherwise it returns false.
func TooManyRequestsError ¶
func TooManyRequestsError(w http.ResponseWriter, msg string)
func Unauthorized ¶
func Unauthorized(w http.ResponseWriter, msg string)
Types ¶
type Client ¶
type Client struct {
ID string
// contains filtered or unexported fields
}
func NewWebSocketClient ¶
func NewWebSocketClient(conn *websocket.Conn, manager *WebSocketManager, topicID string) *Client
type ClientList ¶
type ClientList map[*Client]struct{}
ClientList. TODO: user map[string]*Client (clientID)
type Event ¶
type Event struct {
Type string `json:"type"`
Payload json.RawMessage `json:"payload"`
}
type EventHandler ¶
type HandlerFunc ¶
type HandlerFunc func(w http.ResponseWriter, r *http.Request) error
type NewMessageEvent ¶
type NewMessageEvent struct {
SendMessageEvent
Sent time.Time `json:"sent"`
}
type RateLimiter ¶
type Response ¶
type Response struct {
Status ResponseStatus `json:"status"`
Code string `json:"code,omitempty"`
Message string `json:"message,omitempty"`
Data W `json:"data,omitempty"`
Errors any `json:"errors,omitempty"`
}
func (*Response) WithErrors ¶
func (*Response) WithMessage ¶
func (*Response) WithStatus ¶
func (r *Response) WithStatus(status ResponseStatus) *Response
type ResponseStatus ¶
type ResponseStatus string
const ( StatusOK ResponseStatus = "ok" StatusWarn ResponseStatus = "warning" StatusErr ResponseStatus = "error" StatusFatal ResponseStatus = "fatal" )
type SendMessageEvent ¶
type Server ¶
type Server struct {
IsDev bool
RateLimiter RateLimiter
UserService echosight.UserService
HostService echosight.HostService
DetectorService echosight.DetectorService
RecipientService echosight.RecipientService
PreferenceService echosight.PreferenceService
SessionService echosight.SessionService
MetricReader echosight.MetricReader
Scheduler *observer.Scheduler
EventHandler *eventflow.Engine
Crypter echosight.Crypter
// contains filtered or unexported fields
}
Server is a simple wrapper for e.g. chi mux to use custom hanlders wich returns an error
func NewServer ¶
func NewServer(opts ServerOpts) (*Server, error)
NewServer creates a new EchoSight server with all routes mapped
func (*Server) ServerContext ¶
type ServerOpts ¶
type WebSocketManager ¶
type WebSocketManager struct {
sync.RWMutex
TrustedOrigins []string
// contains filtered or unexported fields
}
func NewWebSocketManager ¶
func NewWebSocketManager(s *Server) *WebSocketManager
func (*WebSocketManager) SendMessage ¶
func (m *WebSocketManager) SendMessage(event Event, c *Client) error
SendMessage sends messages to the clients
Source Files
¶
Click to show internal directories.
Click to hide internal directories.