vis

package
v0.0.0-...-c99117f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
const (
	// PluginManifestFile is the filename of plugin manifest
	PluginManifestFile = "visualizer.plugin"
	// DefaultTitle for page
	DefaultTitle = "Visualizer"
)

Variables

This section is empty.

Functions

func MustEncode

func MustEncode(data interface{}) []byte

MustEncode encodes data to JSON

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 DataValue

type DataValue json.RawMessage

DataValue is the value of a data entry.

type ExecMsgSource

type ExecMsgSource struct {
	Cmd *exec.Cmd
	// contains filtered or unexported fields
}

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) Close

func (s *ExecMsgSource) Close() error

Close closes direction pipes

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) Reset

func (s *MemStateStore) Reset() error

Reset 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

func DataValueMsg(id string, val DataValue) Msg

func ObjectMsg

func ObjectMsg(obj Object) Msg

ObjectMsg creates an object message

func (Msg) Action

func (m Msg) Action() string

Action returns action property

func (Msg) ByKeys

func (m Msg) ByKeys(keys ...string) (v interface{})

ByKeys retrieves a value following the keys

func (Msg) ID

func (m Msg) ID() string

ID returns id property

func (Msg) MustEncode

func (m Msg) MustEncode() string

MustEncode encodes message to JSON

func (Msg) Object

func (m Msg) Object() Object

Object returns object property

func (Msg) Value

func (m Msg) Value() DataValue

Value returns the value property

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 Object

type Object map[string]interface{}

Object is an object containing arbitrary fields

func (Object) ID

func (o Object) ID() string

ID returns object id

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

func (s *Server) AddBuiltin(builtin Builtin) *Server

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

func (s *Server) DataValues() (map[string]DataValue, error)

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

func (s *Server) HandleMessage(a Msg) (err error)

HandleMessage processes one message

func (*Server) Handler

func (s *Server) Handler(ext ServerExt) (http.Handler, error)

Handler creates default http handler

func (*Server) LoadPlugin

func (s *Server) LoadPlugin(dir string) error

LoadPlugin loads plugin from specified directory

func (*Server) Objects

func (s *Server) Objects() (map[string]Object, error)

Objects implements StateStore

func (*Server) RecvMessages

func (s *Server) RecvMessages(msgs []Msg)

RecvMessages implements MessageSink

func (*Server) Remove

func (s *Server) Remove(ids ...string) error

Remove implements StateStore

func (*Server) Reset

func (s *Server) Reset() error

Reset implements StateStore

func (*Server) Serve

func (s *Server) Serve(ext ServerExt) error

Serve runs the server

func (*Server) StatesHandler

func (s *Server) StatesHandler(w http.ResponseWriter, r *http.Request)

StatesHandler is the http handler manipulate object states

func (*Server) Update

func (s *Server) Update(objs ...Object) error

Update implements StateStore

func (*Server) UpdateDataValue

func (s *Server) UpdateDataValue(id string, val DataValue) error

UpdateDataValue implements StateStore

func (*Server) WebSocketHandler

func (s *Server) WebSocketHandler(ws *websocket.Conn)

WebSocketHandler handles websocket connections

type ServerExt

type ServerExt interface {
	AddHandlers(mux *http.ServeMux) error
}

ServerExt extends server handlers

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

type StreamMsgSource struct {
	Reader io.Reader
	Writer io.Writer
}

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL