ui

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: MIT Imports: 25 Imported by: 4

Documentation

Index

Constants

View Source
const ContextBindingName = "context"
View Source
const ReadyFuncName = "Gots"

ReadyFuncName is an async ready function in api object.

Variables

View Source
var ChromeBinary string

Functions

func BasicAuth

func BasicAuth(auth func(user string, pass string) bool) func(http.HandlerFunc) http.HandlerFunc

func NewHtmlRoot

func NewHtmlRoot(html string) *simpleRoot

func NewSimpleRoot

func NewSimpleRoot(files map[string]string) *simpleRoot

func OpenBrowser added in v0.1.4

func OpenBrowser(pageURL string) error

func OpenWebApp added in v0.1.4

func OpenWebApp(url string, x, y, width, height int) error

Types

type Bindable

type Bindable interface {
	Bind(b Bindings)
	BindPrefix(name string, b Bindings)
	BindFunc(name string, fn interface{})
	BindObject(obj interface{})
	BindMap(m map[string]interface{})
	GetBindings() []Bindings
}

type Binder

type Binder interface {
	Bind(b Bindings) error
}

type BindingFunc

type BindingFunc interface{}

type Bindings

type Bindings interface {
	Names() []string
	Map(*UIContext) map[string]BindingFunc
	Error() error
}

Bindings represent an api. Every binding has a name and a callable object.

func Delay

func Delay(names []string, factory func(*UIContext) Bindings) Bindings

func DelayMap

func DelayMap(prototype map[string]interface{}, factory func(*UIContext) Bindings) Bindings

func DelayObject

func DelayObject(prototype interface{}, factory func(*UIContext) Bindings) Bindings

func Func

func Func(name string, fn interface{}) Bindings

func Map

func Map(m map[string]interface{}) Bindings

func Object

func Object(obj interface{}) Bindings

func Prefix

func Prefix(name string, b Bindings) Bindings

type ClientOptions

type ClientOptions struct {
	BlurOnClose bool
}

type Context

type Context struct {
	Seq int `json:"seq"`
	// contains filtered or unexported fields
}

func (*Context) Deadline

func (c *Context) Deadline() (deadline time.Time, ok bool)

func (*Context) Done

func (c *Context) Done() <-chan struct{}

func (*Context) Err

func (c *Context) Err() error

func (*Context) Value

func (c *Context) Value(key interface{}) interface{}

func (*Context) WithCancel

func (c *Context) WithCancel() context.CancelFunc

type FileServer

type FileServer struct {
	Addr          string
	ServerPath    string
	Listener      net.Listener
	Prefix        string // path prefix
	Auth          func(http.HandlerFunc) http.HandlerFunc
	HistoryMode   bool
	ClientOptions *ClientOptions
	// contains filtered or unexported fields
}

func NewFileServer

func NewFileServer(root fs.FS) *FileServer

func (*FileServer) Bind

func (s *FileServer) Bind(b Bindings) error

func (*FileServer) Close

func (s *FileServer) Close() error

func (*FileServer) Done

func (s *FileServer) Done() <-chan struct{}

func (*FileServer) ListenAndServe

func (s *FileServer) ListenAndServe() error

func (*FileServer) ListenAndServeTLS

func (s *FileServer) ListenAndServeTLS(certFile, keyFile string) error

func (*FileServer) ServeExistingServer

func (s *FileServer) ServeExistingServer(server HTTPServer)

func (*FileServer) ServeExistingServerTLS

func (s *FileServer) ServeExistingServerTLS(server HTTPServer)

func (*FileServer) Shutdown

func (s *FileServer) Shutdown(ctx context.Context) error

type Function

type Function struct {
	BindingName string `json:"bindingName"`
	Seq         int    `json:"seq"`
	// contains filtered or unexported fields
}

Function wraps a js callback function.

func (*Function) Call

func (c *Function) Call(args ...interface{}) Value

Call method.

type HTTPServer

type HTTPServer interface {
	Handle(pattern string, handler http.Handler)
}

type HTTPServerFunc

type HTTPServerFunc func(pattern string, handler http.Handler)

func (HTTPServerFunc) Handle

func (f HTTPServerFunc) Handle(pattern string, handler http.Handler)

type ObjectFactory

type ObjectFactory func(*UIContext) interface{}

type Option

type Option func(*uiConfig) error

func AppWindow

func AppWindow(x, y, width, height int) Option

func BlurOnClose

func BlurOnClose(blur bool) Option

func HistoryMode

func HistoryMode(enable bool) Option

func LocalExitDelay

func LocalExitDelay(d time.Duration) Option

LocalExitDelay contorl auto exit behaviour of a local server. By default, when all clients where lost, a local server will wait for a new client and exit if timeout. A local server will exit immediately after any client lost when duration is 0, and never exit when duration is less than 0.

func LocalMapURL

func LocalMapURL(mapURL func(net.Listener) string) Option

func Mode

func Mode(mod string) Option

Mode can be override by a 'MODE=xxx' environment variable. Default value is page.

func OnlineAddr

func OnlineAddr(addr string) Option

func OnlineAttach

func OnlineAttach(existingServer HTTPServer, tls bool) Option

func OnlineAuth

func OnlineAuth(auth func(http.HandlerFunc) http.HandlerFunc) Option

func OnlineListener

func OnlineListener(listener net.Listener) Option

func OnlinePort

func OnlinePort(port int) Option

func OnlinePrefix

func OnlinePrefix(prefix string) Option

func OnlineTLS

func OnlineTLS(certFile, keyFile string) Option

func OpenURL added in v0.1.4

func OpenURL(fn func(string) error) Option

OpenURL is a callback to enable custom frontend. If not set, a browser will be opened.

func Quiet

func Quiet() Option

func Root

func Root(root fs.FS) Option

func RootFiles

func RootFiles(files map[string]string) Option

func RootHtml

func RootHtml(html string) Option

type Page

type Page interface {
	Bind(name string, f interface{}) error
	Eval(js string) Value
	SetReady() error // nofity server ready ( all functions binded )
	Close()
	Done() <-chan struct{}
}

Page of a javascript client.

type RunMode

type RunMode interface {
	IsApp() bool
	IsPage() bool
	IsOnline() bool
	IsLocal() bool
}

type UI

type UI interface {
	Run() error
	Bindable
	RunMode
	Add(name string, child UI) // add sub UI
}

func New

func New(ops ...Option) UI

type UIContext

type UIContext struct {
	Request *http.Request
	Done    <-chan bool
}

type Value

type Value interface {
	Err() error
	To(interface{}) error
	Float() float32
	Int() int
	String() string
	Bool() bool
	Object() map[string]Value
	Array() []Value
}

Value is JSON value or error.

type Window

type Window interface {
	Bind(b Bindings) error
	Open() error
	Server() *FileServer
	SetExitDelay(d time.Duration)
	Eval(js string) Value
	Done() <-chan struct{}
	Close() error
}

func NewChromeApp added in v0.1.4

func NewChromeApp(root fs.FS, x, y int, width, height int, chromeArgs ...string) Window

func NewChromeAppMapURL added in v0.1.4

func NewChromeAppMapURL(root fs.FS, x, y int, width, height int, mapURL func(net.Listener) string, chromeArgs ...string) Window

func NewPage

func NewPage(root fs.FS, openURL func(string) error) Window

func NewPageMapURL

func NewPageMapURL(root fs.FS, openURL func(string) error, mapURL func(net.Listener) string) Window

Jump to

Keyboard shortcuts

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