Documentation
¶
Index ¶
- Variables
- func Asset(name string) ([]byte, error)
- func AssetDir(name string) ([]string, error)
- func AssetInfo(name string) (os.FileInfo, error)
- func AssetNames() []string
- func MustAsset(name string) []byte
- func RestoreAsset(dir, name string) error
- func RestoreAssets(dir, name string) error
- func SyncHandler(gostruct interface{}) http.Handler
- type Conn
- type Pusher
- type State
Constants ¶
This section is empty.
Variables ¶
var ( //MinThrottle is the minimum manual State.Throttle value. //15ms is approximately highest resolution on the JS eventloop. MinThrottle = 15 * time.Millisecond //DefaultThrottle is the default State.Throttle value. DefaultThrottle = 200 * time.Millisecond //DefaultWriteTimeout is the default State.Throttle value. DefaultWriteTimeout = 30 * time.Second //DefaultPingInterval is the default State.PingInterval value. DefaultPingInterval = 25 * time.Second )
var JS = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { filename := "bundle.js" b, _ := Asset(filename) info, _ := AssetInfo(filename) if strings.Contains(req.Header.Get("Accept-Encoding"), "gzip") && w.Header().Get("Content-Encoding") != "gzip" { gb := bytes.Buffer{} g := gzip.NewWriter(&gb) g.Write(b) g.Close() b = gb.Bytes() w.Header().Set("Content-Encoding", "gzip") } buff := bytes.NewReader(b) http.ServeContent(w, req, info.Name(), info.ModTime(), buff) })
JS is an HTTP handler serving the velox.js frontend library
Functions ¶
func Asset ¶
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 ¶
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 ¶
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 MustAsset ¶
MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.
func RestoreAsset ¶
RestoreAsset restores an asset under the given directory
func RestoreAssets ¶
RestoreAssets restores an asset under the given directory recursively
func SyncHandler ¶
SyncHandler is a small wrapper around Sync which simply synchronises all incoming connections. Use Sync if you wish to implement user authentication or any other request-time checks.
Types ¶
type Conn ¶
Conn represents a single live connection being synchronised. ID is current set to the connection's remote address.
func Sync ¶
Sync upgrades a given HTTP connection into a velox connection and synchronises the provided struct with the client. velox takes responsibility for writing the response in the event of failure. Default handlers close the TCP connection on return so when manually using this method, you'll most likely want to block using Conn.Wait().
type Pusher ¶
type Pusher interface {
Push() bool
}
Pusher implements a push method, similar to Flush
type State ¶
type State struct { //configuration Throttle time.Duration `json:"-"` WriteTimeout time.Duration `json:"-"` PingInterval time.Duration `json:"-"` // contains filtered or unexported fields }
State must be embedded into a struct to make it syncable.