web

package
v0.2.2-0...-06a51cc Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2017 License: GPL-3.0 Imports: 25 Imported by: 0

README

web

Contains web server acting as a remote interface for the Regenbox

static assets

Static assets are embedded into binary using go-bindata.

Use the following to generate assets files:

  • go-bindata -pkg web -o assets.go [files...]

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChartsLink = Link{
	Href: "/charts",
	Name: "Charts",
}
View Source
var DefaultConfig = Config{
	User:     NoName,
	Battery:  NoBattery,
	Resistor: 10,
	Web:      DefaultServerConfig,
	Regenbox: regenbox.DefaultConfig,
	Watcher:  regenbox.DefaultWatcherConfig,
	Serial:   regenbox.DefaultSerialConfig,
}
View Source
var DefaultServerConfig = ServerConfig{
	ListenAddr:        "localhost:3636",
	StaticDir:         "static",
	DataDir:           "data",
	WebsocketInterval: util.Duration(time.Second),
}
View Source
var HomeLink = Link{
	Href: "/",
	Name: "Live",
}
View Source
var NoBattery = Battery{}
View Source
var NoName = User{}

Functions

func Asset

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:

data/
  foo.txt
  img/
    a.png
    b.png

then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames

func AssetNames() []string

AssetNames returns the names of the assets.

func Logger

func Logger(handler http.Handler, name string, verbose bool) http.Handler

func MustAsset

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NilHandler

func NilHandler(w http.ResponseWriter, _ *http.Request)

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func StartServer

func StartServer(version string, rbox *regenbox.RegenBox, cfg *Config, cfgPath string, verbose bool)

StartServer starts a new http.Server using provided version, RegenBox & Config. It either doesn't return or panics (http.Listen)

func WrapCustomRW

func WrapCustomRW(wr http.ResponseWriter) http.ResponseWriter

Types

type Battery

type Battery struct {
	BetaRef string // as provided by Regenbox
	Type    string // AAA, AA...
	Voltage int    // in millivolts
	Brand   string // Duracell...
	Model   string // Ultra
}

type ChartLog

type ChartLog struct {
	User          User
	Battery       Battery
	Resistor      int
	CycleType     string
	TargetReached bool
	Reason        string
	TotalDuration util.Duration
	Config        regenbox.Config
	Measures      util.TimeSeries
}

func (ChartLog) FileName

func (cl ChartLog) FileName() string

func (ChartLog) Info

func (cl ChartLog) Info() ChartLogInfo

func (ChartLog) String

func (cl ChartLog) String() string

type ChartLogInfo

type ChartLogInfo struct {
	User      User
	Battery   Battery
	CycleType string
	StartTime time.Time
	EndTime   time.Time
	Interval  util.Duration
	// contains filtered or unexported fields
}

func ListChartLogs

func ListChartLogs(dir string) (err error, infos []ChartLogInfo)

func (ChartLogInfo) FileName

func (cli ChartLogInfo) FileName() string

func (ChartLogInfo) Path

func (cli ChartLogInfo) Path() string

func (ChartLogInfo) String

func (cli ChartLogInfo) String() string

type Config

type Config struct {
	User     User
	Battery  Battery
	Resistor int
	Regenbox regenbox.Config
	Web      ServerConfig
	Watcher  regenbox.WatcherConfig
	Serial   serial.Mode
}

type CustomResponseWriter

type CustomResponseWriter struct {
	http.ResponseWriter
	Status int
}

CustomResponseWriter allows to store current status code of ResponseWriter.

func (*CustomResponseWriter) Header

func (w *CustomResponseWriter) Header() http.Header

func (*CustomResponseWriter) Hijack

func (*CustomResponseWriter) Write

func (w *CustomResponseWriter) Write(data []byte) (int, error)

func (*CustomResponseWriter) WriteHeader

func (w *CustomResponseWriter) WriteHeader(statusCode int)
type Link struct {
	Href, Name string
}

type Server

type Server struct {
	Config   *Config
	Regenbox *regenbox.RegenBox

	sync.Mutex
	// contains filtered or unexported fields
}

func (*Server) Chart

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

Chart encodes ChartLog from path as json to w.

func (*Server) Charts

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

Explorer page

func (*Server) Home

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

Home serves homepage

func (*Server) LiveData

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

LiveData encodes live measurement log as json to w.

func (*Server) RegenboxConfigHandler

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

RegenboxConfigHandler POST: s.Regenbox.SetConfig() (json encoded),

      Regenbox's must be stopped first
GET: gets current s.Regenbox.Config()

func (*Server) RenderCss

func (s *Server) RenderCss(name string, data interface{}) template.CSS

RenderCss renders un-espaced css asset

func (*Server) RenderHtml

func (s *Server) RenderHtml(name string, data interface{}) template.HTML

RenderHtml renders un-espaced html asset

func (*Server) RenderJs

func (s *Server) RenderJs(name string, data interface{}) template.JS

RenderJs renders un-espaced js asset

func (*Server) Snapshot

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

Snapshot encodes snapshot as json to w.

func (*Server) StartRegenbox

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

func (*Server) Static

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

Static server

func (*Server) StopRegenbox

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

func (*Server) Websocket

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

Websocket is the handler to initiate a websocket connection that keeps track of regenbox state and live measurements.

type ServerConfig

type ServerConfig struct {
	ListenAddr        string
	StaticDir         string
	DataDir           string
	WebsocketInterval util.Duration
	// contains filtered or unexported fields
}

type TemplateData

type TemplateData struct {
	*Config
	Link      Link
	DataDir   string
	CycleMsg  *regenbox.CycleMessage
	ChartLogs []ChartLogInfo
	Error     error
	Version   string
}

type User

type User struct {
	BetaId string // as provided by Regenbox
	Name   string
}

Jump to

Keyboard shortcuts

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