client

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2020 License: AGPL-3.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClickCursor seed.Option

ClickCursor is an option that is added to all OnClicks.

Functions

func Decrypt

func Decrypt(data string) []byte

func Element

func Element(c seed.Seed) string

Element returns the js.Element of the given seed.

func Encrypt

func Encrypt(data []byte) string

Encrypt encrypts data with the session encryption scheme.

func Handler

func Handler(w http.ResponseWriter, r *http.Request, id string)

Handler returns a handler for handling remote procedure calls.

func ID

func ID(c seed.Seed) string

ID returns the client ID of this seed.

func Key

func Key() (key [32]byte)

Key returns the key used by session to encrypt data. Reads key from SESSION_KEY env. Will create a key and store it in seed.Dir if it env is not set.

func On

func On(event string, do ...Script) seed.Option

On is called when the seed has the given event triggered.

func OnChange

func OnChange(do ...Script) seed.Option

OnChange is called when the seed is changed by client interaction.

func OnClick

func OnClick(do ...Script) seed.Option

OnClick is called when the seed is clicked by the client.

func OnEnterKey

func OnEnterKey(do ...Script) seed.Option

OnEnterKey is called when the client presses the Enter key whilst focused on this seed.

func OnError

func OnError(do func(err String) Script) seed.Option

OnError calls the provided script when there is an error not handled by this seed or any children seeds.

func OnInput

func OnInput(do ...Script) seed.Option

OnInput is called when the seed recieves input from the client.

func OnLoad

func OnLoad(do ...Script) seed.Option

OnLoad is called when the seed is loaded by the client. this will only be called once per app-launch, or in the case of dynamic content, once when the seed is created.

func OnRender

func OnRender(do ...Script) seed.Option

OnRender is called whenever this seed is asked to render itself.

func Option

func Option(o seed.Option, q js.Ctx) seed.Option

Option converts an option into a client option.

func RegisterRenderer

func RegisterRenderer(r Renderer)

func RegisterRootRenderer

func RegisterRootRenderer(r Renderer)

func Render

func Render(root seed.Seed) []byte

Render renders the Javascript attached to this seed and its children.

func Reverse

func Reverse(o seed.Option, q js.Ctx) seed.Option

Reverse converts an option into a reversed client option.

func SetID

func SetID(id string) seed.Option

func Split

func Split(s String, sep String) js.Array

Split returns an array of strings based on the split seperator.

func Unique

func Unique() string

Unique returns a unique string suitable for variable names.

Types

type Bool

type Bool = js.AnyBool

func NewBool

func NewBool(from bool) Bool

type Compound

type Compound interface {
	Components() []Value
}

Compound values have dependent components.

type Cookie struct {
	Name   string
	MaxAge time.Duration
}

Cookie is an client-request associated value that is encrypted by default.

func NewCookie

func NewCookie(name string) Cookie

NewCookie creates a new cookie with the given name.

type Data

type Data struct {
	On map[string]js.Script
	// contains filtered or unexported fields
}

Data on how to handle client events.

type File

type File interface {
	Value
	GetFile() js.Value
}

type Float

type Float = js.AnyNumber

func NewFloat64

func NewFloat64(from float64) Float

type Function

type Function = js.AnyFunction

func NewFunction

func NewFunction(from js.Script) Function

type IfElseChain

type IfElseChain struct {
	Script
}

IfElseChain allows else to be called on it.

func If

func If(condition Bool, do ...Script) IfElseChain

If runs the provided scripts if the clients condition is true.

func (IfElseChain) Else

func (chain IfElseChain) Else(do ...Script) Script

Else runs the provided scripts if the preceding conditions were false.

type Int

type Int = js.AnyNumber

func NewInt

func NewInt(from int) Int

type Mode

type Mode int8

Mode on the client, when processing a seed option.

const (
	AddTo Mode = 1
	Undo  Mode = 2
)

SeedTypes

func Seed

func Seed(c seed.Seed) (Mode, js.Ctx)

Seed returns the mode and ctx of the given seed.

type Name

type Name struct {
	String
}

func NameAs

func NameAs(s String) Name

type Object

type Object = js.AnyObject

type Redirect

type Redirect string

Redirect is a special error-type that signifies that a redirect is required to complete the request.

func (Redirect) Error

func (r Redirect) Error() string

type Renderer

type Renderer func(root seed.Seed) []byte

type Request

type Request struct {
	Path string

	Response io.Writer
	// contains filtered or unexported fields
}

Request holds the metadata about an incomming request from the client.

func NewRequest

func NewRequest(w http.ResponseWriter, r *http.Request) Request

NewRequest returns a new request from the given values.

func (Request) Arg

func (cr Request) Arg(name string) string

Arg returns the named query value with the given name.

func (Request) Get

func (cr Request) Get(c Cookie) string

Get gets the value of a cookie associated with requests by this client.

func (Request) Local

func (cr Request) Local() (local bool)

Local returns true if the user is connecting from localhost.

func (Request) Serve

func (cr Request) Serve(handler http.Handler)

Serve serves a http.Handler as a response to this request.

func (Request) Set

func (cr Request) Set(c Cookie, value string)

Set sets the value of a cookie associated with requests by this client.

type Requesty

type Requesty interface {
	FromRequest(Request) error
}

Requesty is any type that can load itself from a Request.

type Script

type Script = js.AnyScript

func Adopt

func Adopt(c seed.Seed) Script

Adopt returns and removes the script from the given seed.

func After

func After(duration time.Duration, do ...Script) Script

After runs the given scripts after the specified duration has passed.

func Cancel

func Cancel() Script

Cancel cancels the current script.

func Download

func Download(fn interface{}, args ...Value) Script

func Go

func Go(fn interface{}, args ...Value) Script

Go requests the client to call the given Go function in a new goroutine, with the given client Values automatically converted to equivalent Go values and are passed to the given function. The function can optionally take a Ctx as the first argument, if so, then it is passed to the function and arguments are assigned to the following arguments.

func NewScript

func NewScript(do ...Script) Script

func Open

func Open(url String) Script

Open asks the client to open the specified URL.

func Print

func Print() Script

Print asks the client to print the current page.

func Run

func Run(fn interface{}, args ...Value) Script

Run runs a go function, blocking until it completes.

func Throw

func Throw(err String) Script

Throw throws the provided error.

type Stream

type Stream struct {
	// contains filtered or unexported fields
}

Stream is an incomming data steam from the client.

func (Stream) Close

func (s Stream) Close() error

Close implements io.Closer

func (Stream) Name

func (s Stream) Name() string

Name returns the name of the steam, if a file is being sent, this is the name of the file.

func (Stream) Read

func (s Stream) Read(b []byte) (int, error)

Read implements io.Reader

func (Stream) Size

func (s Stream) Size() int64

Size returns the expected size of the stream.

type String

type String js.AnyString

String is a readonly client-typed string.

func NewString

func NewString(literal string) String

NewString returns a client-typed String from the given string.

type Value

type Value = js.AnyValue

Value is a readonly client-typed value.

func Call

func Call(fn interface{}, args ...Value) Value

Call calls a go function and returns the result.

func FlattenComponents

func FlattenComponents(components ...Value) []Value

FlattenComponents flattens the components to their root components.

func ValueOf

func ValueOf(any interface{}) Value

ValueOf returns a client-typed value of the given argument.

Directories

Path Synopsis
Package clientsafe provides an error type that is safe to show to clients.
Package clientsafe provides an error type that is safe to show to clients.
Package clientzip provides clientside zipping functionality.
Package clientzip provides clientside zipping functionality.
if
all
any
not
the

Jump to

Keyboard shortcuts

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