Documentation
¶
Index ¶
- Constants
- func MustEncode(data interface{}) []byte
- type Builtin
- type DataValue
- type ExecMsgSource
- type ListenerSource
- type MemStateStore
- func (s *MemStateStore) DataValues() (data map[string]DataValue, err error)
- func (s *MemStateStore) Objects() (objs map[string]Object, err error)
- func (s *MemStateStore) Remove(ids ...string) error
- func (s *MemStateStore) Reset() error
- func (s *MemStateStore) Update(objs ...Object) error
- func (s *MemStateStore) UpdateDataValue(id string, val DataValue) error
- type MessageSink
- type Msg
- type MsgDecoder
- type MsgSource
- type Object
- type PageContext
- type PluginManifest
- type Server
- func (s *Server) AddBuiltin(builtin Builtin) *Server
- func (s *Server) AssetsHandler(w http.ResponseWriter, r *http.Request)
- func (s *Server) DataValues() (map[string]DataValue, error)
- func (s *Server) GenerateIndexPage(fs http.FileSystem) (string, error)
- func (s *Server) HandleIndex(w http.ResponseWriter, r *http.Request, fs http.FileSystem)
- func (s *Server) HandleMessage(a Msg) (err error)
- func (s *Server) Handler(ext ServerExt) (http.Handler, error)
- func (s *Server) LoadPlugin(dir string) error
- func (s *Server) Objects() (map[string]Object, error)
- func (s *Server) RecvMessages(msgs []Msg)
- func (s *Server) Remove(ids ...string) error
- func (s *Server) Reset() error
- func (s *Server) Serve(ext ServerExt) error
- func (s *Server) StatesHandler(w http.ResponseWriter, r *http.Request)
- func (s *Server) Update(objs ...Object) error
- func (s *Server) UpdateDataValue(id string, val DataValue) error
- func (s *Server) WebSocketHandler(ws *websocket.Conn)
- type ServerExt
- type StateStore
- type StreamMsgSource
Constants ¶
const ( PropAction = "action" PropObject = "object" PropValue = "value" PropData = "data" PropID = "id" ActionReset = "reset" ActionObject = "object" ActionData = "data" ActionAsset = "asset" ActionRemove = "remove" )
Properties and Action names
const ( // PluginManifestFile is the filename of plugin manifest PluginManifestFile = "visualizer.plugin" // DefaultTitle for page DefaultTitle = "Visualizer" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Builtin ¶
type Builtin struct { Path string Visualizer PageContext Handler http.Handler }
Builtin is used to extend the index page from application using this package directly
type ExecMsgSource ¶
ExecMsgSource spawns an external process and use stdin/stdout to exchange messages
func NewExecMsgSource ¶
func NewExecMsgSource(prog string, args ...string) (s *ExecMsgSource, err error)
NewExecMsgSource creates a new ExecMsgSource using command line
func (*ExecMsgSource) ProcessMessages ¶
func (s *ExecMsgSource) ProcessMessages(sink MessageSink) error
ProcessMessages implements MsgSource
func (*ExecMsgSource) RecvMessages ¶
func (s *ExecMsgSource) RecvMessages(msgs []Msg)
RecvMessages implements MessageSink
type ListenerSource ¶
type ListenerSource struct {
// contains filtered or unexported fields
}
func NewListenerSource ¶
func NewListenerSource(ln net.Listener) *ListenerSource
func (*ListenerSource) ProcessMessages ¶
func (s *ListenerSource) ProcessMessages(sink MessageSink) error
func (*ListenerSource) RecvMessages ¶
func (s *ListenerSource) RecvMessages(msgs []Msg)
type MemStateStore ¶
type MemStateStore struct {
// contains filtered or unexported fields
}
MemStateStore is an in-memory implementation of StateStore
func (*MemStateStore) DataValues ¶
func (s *MemStateStore) DataValues() (data map[string]DataValue, err error)
DataValues implements StateStore
func (*MemStateStore) Objects ¶
func (s *MemStateStore) Objects() (objs map[string]Object, err error)
Objects implements StateStore
func (*MemStateStore) Remove ¶
func (s *MemStateStore) Remove(ids ...string) error
Remove implements StateStore
func (*MemStateStore) Update ¶
func (s *MemStateStore) Update(objs ...Object) error
Update implements StateStore
func (*MemStateStore) UpdateDataValue ¶
func (s *MemStateStore) UpdateDataValue(id string, val DataValue) error
type MessageSink ¶
type MessageSink interface {
RecvMessages([]Msg)
}
MessageSink defines a message receiver
func SinkMessage ¶
func SinkMessage(sink func([]Msg)) MessageSink
SinkMessage wraps a func to be a MessageSink
type Msg ¶
type Msg map[string]interface{}
Msg is message with flex field
func DataValueMsg ¶
type MsgDecoder ¶
type MsgDecoder struct {
// contains filtered or unexported fields
}
MsgDecoder decodes message from a stream
func NewMsgDecoder ¶
func NewMsgDecoder(stream io.Reader) *MsgDecoder
NewMsgDecoder creates a decoder from a stream
func (*MsgDecoder) Decode ¶
func (d *MsgDecoder) Decode() (msgs []Msg, err error)
Decode decodes a list of messages
type MsgSource ¶
type MsgSource interface { MessageSink // ProcessMessages is a loop to drain messages and send to // provided MessageSink. The returned error can be io.EOF to // indicate end of message processing, or any other errors to // leave for application to determine call ProcessMessages again // or simply abort. Returning nil usually indicates there are // more messages, and application will call ProcessMessages again ProcessMessages(MessageSink) error }
MsgSource is the source of message, and also accepts messages
type PageContext ¶
type PageContext struct { Stylesheets []string `json:"stylesheets" yaml:"stylesheets"` Scripts []string `json:"scripts" yaml:"scripts"` Title string `json:"-" yaml:"-"` }
PageContext defines the extensive content in page
type PluginManifest ¶
type PluginManifest struct { Name string `json:"name" yaml:"name"` Visualizer PageContext `json:"visualizer" yaml:"visualizer"` }
PluginManifest is the content of plugin manifest file
func LoadPluginManifest ¶
func LoadPluginManifest(dir string) (*PluginManifest, error)
LoadPluginManifest loads plugin manifest from specified directory
type Server ¶
type Server struct { Host string Port int Listener net.Listener States StateStore MsgSink MessageSink Logger *logger.Logger LocalWebDir string WebContentDir string Builtins []Builtin Title string // contains filtered or unexported fields }
Server serve static pages and APIs
func (*Server) AddBuiltin ¶
AddBuiltin registers a builtin extension
func (*Server) AssetsHandler ¶
func (s *Server) AssetsHandler(w http.ResponseWriter, r *http.Request)
AssetsHandler is the http handler serving assets
func (*Server) DataValues ¶
DataValues implements StateStore
func (*Server) GenerateIndexPage ¶
func (s *Server) GenerateIndexPage(fs http.FileSystem) (string, error)
GenerateIndexPage generates index.html
func (*Server) HandleIndex ¶
func (s *Server) HandleIndex(w http.ResponseWriter, r *http.Request, fs http.FileSystem)
HandleIndex generates index HTML file
func (*Server) HandleMessage ¶
HandleMessage processes one message
func (*Server) LoadPlugin ¶
LoadPlugin loads plugin from specified directory
func (*Server) RecvMessages ¶
RecvMessages implements MessageSink
func (*Server) StatesHandler ¶
func (s *Server) StatesHandler(w http.ResponseWriter, r *http.Request)
StatesHandler is the http handler manipulate object states
func (*Server) UpdateDataValue ¶
UpdateDataValue implements StateStore
func (*Server) WebSocketHandler ¶
WebSocketHandler handles websocket connections
type StateStore ¶
type StateStore interface { Objects() (map[string]Object, error) DataValues() (map[string]DataValue, error) Reset() error Update(objs ...Object) error UpdateDataValue(id string, val DataValue) error Remove(ids ...string) error }
StateStore saves the current object states
type StreamMsgSource ¶
StreamMsgSource implements MsgSource simply using Reader/Writer for line-based JSON encoded messages in plain text
func (*StreamMsgSource) ProcessMessages ¶
func (s *StreamMsgSource) ProcessMessages(sink MessageSink) error
ProcessMessages implements MsgSource
func (*StreamMsgSource) RecvMessages ¶
func (s *StreamMsgSource) RecvMessages(msgs []Msg)
RecvMessages implements MessageSink