gui

package
v5.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2017 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package gui provides tool for a HTML based modificator for Go values.

Package gui contains code to render an arbitrary Go value as a HTML form and update the value from the submitted form data. The generated HTML can include documentation in the form of tooltips.

Global State

To render and update a Go value to/from a HTML form package gui needs information about the types like documentation of types and fields, which type satisfies which interface and which struct fields should not be rendered. This information is kept in package scoped variables which is ugly but easy:

Index

Constants

This section is empty.

Variables

View Source
var CSS = `` /* 1910-byte string literal not displayed */

CSS contains some minimal CSS definitions needed to render the HTML properly.

View Source
var Favicon = []byte{}/* 318 elements not displayed */

Favicon is a blue/red "ht" in 16x16 ico format.

View Source
var Implements = make(map[reflect.Type][]reflect.Type)

Implements is the global lookup of what types implement a given interface

View Source
var Typedata = make(map[reflect.Type]Typeinfo)

Typedata is the global registry to look up infos for types.

Functions

func RegisterImplementation

func RegisterImplementation(iface interface{}, typ interface{})

RegisterImplementation records that iface is implemented by typ. To register that AbcWriter implements the Writer interface use:

RegisterImplementation((*Writer)(nil), AbcWriter{})

func RegisterType

func RegisterType(typ interface{}, info Typeinfo)

RegisterType registers the given info for typ in Typedata.

Types

type Fieldinfo

type Fieldinfo struct {
	Doc       string         // Doc is the field documentation
	Multiline bool           // Multiline allows multiline strings
	Const     bool           // Const values are unchangeable (display only)
	Only      []string       // Only contains the set of allowed values (pick one)
	Any       []string       // Any contains the set of allowed values (pick any)
	Validate  *regexp.Regexp // Validate this field
	Omit      bool           // Omit this field
}

Fieldinfo contains metadata to fields of structs.

type Message

type Message struct {
	Type string
	Text string
}

Message is a typed text message.

type Typeinfo

type Typeinfo struct {
	// Doc is the documentation for the type as a whole.
	Doc string

	// Fields contains field metadata indexed by field name.
	Field map[string]Fieldinfo
}

Typeinfo contains metadata for types.

type Value

type Value struct {
	// Current is the current value.
	Current interface{}

	// Last contains the last values
	Last []interface{}

	// Path is the path prefix applied to this value.
	Path string

	// Messages contains messages to be rendered for paths. E.g.:
	//   Test.Request.Timeout => Message{typ:error, txt=wrong}
	Messages map[string][]Message
	// contains filtered or unexported fields
}

Value contains a value to be displayed and updated through a HTML GUI.

func NewValue

func NewValue(val interface{}, path string) *Value

NewValue creates a new Value from val.

func (*Value) BinaryData

func (v *Value) BinaryData(path string) ([]byte, error)

BinaryData returns the string or byte slice addressed by path.

func (*Value) PushCurrent

func (v *Value) PushCurrent()

PushCurrent stores the Current value in v to the list of Last values. This allows to checkpoint the state of v for subsequent undoes to one of the Pushed states.

func (*Value) Render

func (v *Value) Render() ([]byte, error)

Render v's Current value. The returned byte slice must neither be modified nor kept longer then up to the next call of Render.

func (*Value) Update

func (v *Value) Update(form url.Values) (string, errorlist.List)

Update v with data from the received HTML form. It returns the path of the most prominent field (TODO: explain better).

type ValueError

type ValueError struct {
	Path string // path of field
	Err  error  // original error
}

ValueError is an error from invalid form input, e.g. "foo" to an time.Duration field.

func (ValueError) Error

func (ve ValueError) Error() string

Jump to

Keyboard shortcuts

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