Documentation
¶
Index ¶
- func GenerateJSCode(obj interface{}) string
- func LaunchBrowser(url string) *exec.Cmd
- func MarshalDiff(v interface{}) ([]byte, error)
- type Dispatcher
- type Field
- type Model
- type ModelIface
- type ModelState
- type Window
- func (s *Window) Call(fname string, args ...interface{}) error
- func (s *Window) Handle(pattern string, handler http.Handler)
- func (s *Window) SendEvent(name string, event interface{}) error
- func (s *Window) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Window) Start() error
- func (s *Window) SyncModel() error
- func (s *Window) Wait()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateJSCode ¶
func GenerateJSCode(obj interface{}) string
GenerateJSCode creates a client-side javascript proxy for the object.
func LaunchBrowser ¶
LaunchBrowser opens the URL in the default browser.
Types ¶
type Dispatcher ¶
type Dispatcher struct {
// contains filtered or unexported fields
}
Dispatcher can invoke functions on an object. A function call is passed in as a JSON message, the function is called and the result is returned as a JSON message.
func NewDispatcher ¶
func NewDispatcher(obj interface{}) *Dispatcher
NewDispatcher creates a new dispatcher for the object
func (*Dispatcher) Dispatch ¶
func (d *Dispatcher) Dispatch(inv *invocation) ([]byte, error)
Dispatch decodes the JSON msg and invokes a function on the object. It returns a JSON encoded return message.
type Field ¶
type Field struct {
// contains filtered or unexported fields
}
A Field represents a single field found in a struct.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model implements synchronization between the GO Model and the JavaScript Model in the browser. To use Model, build a model like this:
type MyModel struct { Model Value int OtherValue string }
It is possible to build a hierarchy of models. A model can contain another child model or point to a child model. The graphs of models must form a tree at all times.
type RootModel struct { Model M1 *MyModel M2 MyModel }
func (*Model) ModelChildDirty ¶
func (m *Model) ModelChildDirty()
ModelChildDirty marks that a child model requires synchronization.
func (*Model) ModelDirty ¶
func (m *Model) ModelDirty()
ModelDirty marks the object as requiring synchronization. The parent Models are automatically marked with ModelChildDirty.
func (*Model) ModelState ¶
func (m *Model) ModelState() ModelState
ModelState returns the synchronization state of the Model object.
func (*Model) ModelSwapIndex ¶
ModelSwapIndex returns the current index of the model object inside its containing array. This index is replace with the new index passed as parameter to this function.
func (*Model) ModelSynced ¶
func (m *Model) ModelSynced()
ModelSynced marks the object as being successfully synched. This does not affect parent or child models.
func (*Model) ModelTestSync ¶
func (m *Model) ModelTestSync(parent ModelIface, field *Field) ModelState
ModelTestSync returns the resulting synchronization state of the Model object. If a model object is moved to another parent of another field of the same parent, then the model object will be resynchronized.
type ModelIface ¶
type ModelIface interface { ModelDirty() ModelChildDirty() ModelSynced() ModelState() ModelState ModelTestSync(parent ModelIface, field *Field) ModelState ModelSwapIndex(index int) int ModelID() int }
ModelIface is implemented by Model.
type ModelState ¶
type ModelState int
ModelState describes the synchronization state of a Model object
const ( // ModelNew means that the Model object has not yet been synched ModelNew ModelState = 0 // ModelDirty means that fields of the Model object have been modified // and need synchronization. // In addition, some child Models may be dirty as well. ModelDirty ModelState = 1 // ModelChildDirty means that a child (or indirect child) Model is dirty. ModelChildDirty ModelState = 2 // ModelSynced means that the Model and all of its children is synched. ModelSynced ModelState = 3 )
type Window ¶
type Window struct {
// contains filtered or unexported fields
}
Window opens a new browser window and handles the http communication between the Go process and the browser window.
func NewWindow ¶
func NewWindow(initialPath string, remote interface{}, model ModelIface) *Window
NewWindow creates a new HTTP server. Call Start() to run the server on a system-chosen port via the loopback-device and to launch the UI in the browser. The browser will open the `initialPath`, e.g. "/". The functions of the `remote` interface can be called from JavaScript. The `model` is synced to the browser, i.e. all changes made in GO are synced to the browser.
func (*Window) Call ¶
Call invokes a function in the browser. Call is async, i.e. it does not wait for the browser to complete the function call and the result is not transmitted back to the server.
func (*Window) ServeHTTP ¶
func (s *Window) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP handles incoming HTTP requests, checks authentication via the auth cookie and checks for CSRF attacks via Referer and Origin header fields. Do not call this function from the application code.
func (*Window) Start ¶
Start starts the web server and returns after the UI has either been opened or if the UI could not be started.