Documentation
¶
Overview ¶
Package httpapi provides the HTTP UI/API server for centaurx.
Index ¶
- func ListenAndServe(ctx context.Context, addr string, handler http.Handler) error
- type Authenticator
- type CommandHandler
- type Config
- type Hub
- func (h *Hub) OnOutput(event schema.OutputEvent)
- func (h *Hub) OnSystemOutput(event schema.SystemOutputEvent)
- func (h *Hub) OnTabEvent(event schema.TabEvent)
- func (h *Hub) Replay(userID schema.UserID, after uint64) []StreamEvent
- func (h *Hub) Subscribe(userID schema.UserID) (<-chan StreamEvent, func(), uint64, []StreamEvent)
- type Server
- type SnapshotPayload
- type StreamEvent
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Authenticator ¶
type Authenticator interface {
Authenticate(username, password, totp string) error
ChangePassword(username, currentPassword, totp, newPassword string) error
}
Authenticator verifies username, password, and totp.
type CommandHandler ¶
type CommandHandler interface {
Handle(ctx context.Context, userID schema.UserID, tabID schema.TabID, input string) (bool, error)
}
CommandHandler routes slash commands.
type Config ¶
type Config struct {
Addr string
SessionCookie string
SessionTTLHours int
SessionStorePath string
BaseURL string
BasePath string
InitialBufferLines int
UIMaxBufferLines int
}
Config defines HTTP API and UI settings.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub broadcasts events per user.
func (*Hub) OnOutput ¶
func (h *Hub) OnOutput(event schema.OutputEvent)
OnOutput implements core.EventSink.
func (*Hub) OnSystemOutput ¶
func (h *Hub) OnSystemOutput(event schema.SystemOutputEvent)
OnSystemOutput implements core.EventSink.
func (*Hub) OnTabEvent ¶
OnTabEvent implements core.EventSink.
func (*Hub) Replay ¶
func (h *Hub) Replay(userID schema.UserID, after uint64) []StreamEvent
Replay returns events after the provided seq.
func (*Hub) Subscribe ¶
func (h *Hub) Subscribe(userID schema.UserID) (<-chan StreamEvent, func(), uint64, []StreamEvent)
Subscribe registers a subscriber for a user.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server serves the HTTP API and UI.
func NewServer ¶
func NewServer(cfg Config, service core.Service, handler CommandHandler, authStore Authenticator, hub *Hub) *Server
NewServer constructs an HTTP server.
func (*Server) SetBaseContext ¶
SetBaseContext sets the parent context for session lifetimes.
type SnapshotPayload ¶
type SnapshotPayload struct {
Tabs []schema.TabSnapshot `json:"tabs"`
ActiveTab schema.TabID `json:"active_tab"`
Buffers map[schema.TabID]schema.BufferSnapshot `json:"buffers"`
System schema.SystemBufferSnapshot `json:"system"`
Theme schema.ThemeName `json:"theme,omitempty"`
}
SnapshotPayload seeds client state on connect.
type StreamEvent ¶
type StreamEvent struct {
Seq uint64 `json:"seq"`
Type string `json:"type"`
TabEvent string `json:"tab_event,omitempty"`
TabID schema.TabID `json:"tab_id,omitempty"`
Lines []string `json:"lines,omitempty"`
Tab *schema.TabSnapshot `json:"tab,omitempty"`
ActiveTab schema.TabID `json:"active_tab,omitempty"`
Theme schema.ThemeName `json:"theme,omitempty"`
Snapshot *SnapshotPayload `json:"snapshot,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
StreamEvent is sent to SSE clients.