wok

package module
v0.0.0-...-ad26605 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2020 License: Apache-2.0 Imports: 17 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{}

DefaultOptions are the options which apply to plans by default

Functions

func IsNil

func IsNil(plan Plan) bool

IsNil checks whether the given plan is empty or not

func ToHeader

func ToHeader(params Params, route ...string) string

ToHeader maps a route path to a header value

Types

type CallData

type CallData struct {
	Name string
	url.Values
}

CallData holds a call's data

type Controller

type Controller interface {
	Plan() Plan
	Resolve(string) Controller
}

Controller represents a controller of the routing tree

type Default

type Default struct{}

Default implements the default controller

func (Default) Plan

func (controller Default) Plan() Plan

Plan returns the plan for this controller

func (Default) Resolve

func (controller Default) Resolve(id string) Controller

Resolve returns the nth child of this controller

type HandleOptions

type HandleOptions struct {
	Root       Controller
	HeaderName string
	Route      []string
	Params
}

HandleOptions wraps request.Handle options

type Handler

type Handler struct {
	Root             func() Controller
	RootName         string
	RouteHeader      string
	DepsHeader       string
	InstanceIDHeader string
	InputBuffer      int
	websocket.Upgrader
	way.Router
}

Handler implements an HTTP handler which provides wok requests

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Operator

type Operator interface {
	Map(Options) Options
}

Operator represents an entity capable of applying transformations to certain options

type Options

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

Options holds the list of options selected for a given plan

func AJAX

func AJAX() Options

AJAX runs plans on AJAX

func Always

func Always() Options

Always runs plans even if it wouldn't be necessary

func Call

func Call(calls ...string) Options

Call runs this plan when the request matches one of the provided calls

func Command

func Command(commands ...wit.Command) Options

Command applies given commands directly

func Delete

func Delete() Options

Delete is an alias for Method("DELETE")

func Do

func Do(fn func(r ReadOnlyRequest)) Options

Do does something with the request without returning a delta

func Excl

func Excl() Options

Excl runs plans exclusively, no other plan is allowed to run at the same time

func Fork

func Fork(fn func(o Options) Plan) Options

Fork adds the returned plan to the plan chain

func Get

func Get() Options

Get is an alias for Method("GET", "HEAD")

func Handle

func Handle(fn func(r Request) wit.Command) Options

Handle always applies the command returned by the provided function

func Method

func Method(methods ...string) Options

Method runs this plan when the request matches one of the provided methods

func Navigation() Options

Navigation runs plans on navigation

func NoCall

func NoCall(calls ...string) Options

NoCall runs this plan when the request doesn't match one of the provided calls

func NoDelete

func NoDelete() Options

NoDelete is an alias for NoMethod("DELETE")

func NoGet

func NoGet() Options

NoGet is an alias for NoMethod("GET", "HEAD")

func NoMethod

func NoMethod(methods ...string) Options

NoMethod runs this plan when the request doesn't match one of the provided methods

func NoPatch

func NoPatch() Options

NoPatch is an alias for NoMethod("PATCH")

func NoPost

func NoPost() Options

NoPost is an alias for NoMethod("POST")

func NoPut

func NoPut() Options

NoPut is an alias for NoMethod("PUT")

func NoSocket

func NoSocket() Options

NoSocket doesn't run plans on socket request

func Patch

func Patch() Options

Patch is an alias for Method("PATCH")

func Post

func Post() Options

Post is an alias for Method("POST")

func Put

func Put() Options

Put is an alias for Method("PUT")

func Run

func Run(fn func(r Request) wit.Command) Options

Run applies the command returned by the provided function

func Socket

func Socket() Options

Socket runs plans on socket request

func Sync

func Sync() Options

Sync runs plans sequentially

func Tap

func Tap(fn func(r ReadOnlyRequest)) Options

Tap does something with the request without returning a delta

func With

func With(params ...string) Options

With makes the given list of parameters available to the derived plans

func (Options) AJAX

func (o Options) AJAX() Options

AJAX runs plans on AJAX

func (Options) Always

func (o Options) Always() Options

Always runs plans even if it wouldn't be necessary

func (Options) Call

func (o Options) Call(calls ...string) Options

Call runs this plan when the request matches one of the provided calls

func (Options) Command

func (o Options) Command(commands ...wit.Command) Options

Command applies given commands directly

func (Options) Delete

func (o Options) Delete() Options

Delete is an alias for Method("DELETE")

func (Options) Do

func (o Options) Do(fn func(r ReadOnlyRequest)) Options

Do always does something with the request without returning a delta

func (Options) Excl

func (o Options) Excl() Options

Excl runs plans exclusively, no other plan is allowed to run at the same time

func (Options) Fork

func (o Options) Fork(fn func(o Options) Plan) Options

Fork adds the returned plan to the plan chain

func (Options) Get

func (o Options) Get() Options

Get is an alias for Method("GET", "HEAD")

func (Options) Handle

func (o Options) Handle(fn func(r Request) wit.Command) Options

Handle always applies the command returned by the provided function

func (Options) Method

func (o Options) Method(methods ...string) Options

Method runs this plan when the request matches one of the provided methods

func (Options) Navigation

func (o Options) Navigation() Options

Navigation runs plans on navigation

func (Options) NoCall

func (o Options) NoCall(calls ...string) Options

NoCall runs this plan when the request doesn't match one of the provided calls

func (Options) NoDelete

func (o Options) NoDelete() Options

NoDelete is an alias for NoMethod("DELETE")

func (Options) NoGet

func (o Options) NoGet() Options

NoGet is an alias for NoMethod("GET", "HEAD")

func (Options) NoMethod

func (o Options) NoMethod(methods ...string) Options

NoMethod runs this plan when the request doesn't match one of the provided methods

func (Options) NoPatch

func (o Options) NoPatch() Options

NoPatch is an alias for NoMethod("PATCH")

func (Options) NoPost

func (o Options) NoPost() Options

NoPost is an alias for NoMethod("POST")

func (Options) NoPut

func (o Options) NoPut() Options

NoPut is an alias for NoMethod("PUT")

func (Options) NoSocket

func (o Options) NoSocket() Options

NoSocket doesn't run plans on socket request

func (Options) Patch

func (o Options) Patch() Options

Patch is an alias for Method("PATCH")

func (Options) Pipe

func (o Options) Pipe(operators ...Operator) Options

Pipe applies given operators one after another

func (Options) Post

func (o Options) Post() Options

Post is an alias for Method("POST")

func (Options) Procedure

func (o Options) Procedure() Procedure

Procedure returns the computed procedure

func (Options) Put

func (o Options) Put() Options

Put is an alias for Method("PUT")

func (Options) Run

func (o Options) Run(fn func(r Request) wit.Command) Options

Run applies the command returned by the provided function

func (Options) Socket

func (o Options) Socket() Options

Socket runs plans on socket request

func (Options) Sync

func (o Options) Sync() Options

Sync runs plans sequentially

func (Options) Tap

func (o Options) Tap(fn func(r ReadOnlyRequest)) Options

Tap does something with the request without returning a delta

func (Options) With

func (o Options) With(params ...string) Options

With makes the given list of parameters available to the derived plans

type Params

type Params = map[string][]string

Params hold the list of request parameters

type Plan

type Plan interface {
	Procedure() Procedure
}

Plan encapsulates a procedure

var Nil Plan = Procedure{}

Nil represents an effectless plan

func Deps

func Deps(handler func(string) wit.Command) Plan

Deps handles loaded dependencies

func List

func List(plans ...Plan) Plan

List groups several plans together

type Procedure

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

Procedure describes how to handle a certain request

func (Procedure) Procedure

func (p Procedure) Procedure() Procedure

Procedure returns this procedure itself

type ReadOnlyRequest

type ReadOnlyRequest struct {
	*http.Request
	context.Context
	*sync.Mutex
	way.Router
	url.Values
	InstanceID    string
	OldParams     url.Values
	IsNavigation  bool
	IsSocket      bool
	InitialLoad   bool
	Call          CallData
	Input         <-chan url.Values
	Output        chan<- wit.Command
	RequestHeader http.Header
}

ReadOnlyRequest wraps a read-only HTTP request

func (ReadOnlyRequest) ClientID

func (r ReadOnlyRequest) ClientID() string

ClientID returns InstanceID, useful to meet interface definitions

func (ReadOnlyRequest) CmdCh

func (r ReadOnlyRequest) CmdCh() chan<- wit.Command

CmdCh returns Output, useful to meet interface definitions

func (ReadOnlyRequest) FromHeader

func (r ReadOnlyRequest) FromHeader(header string) (Params, []string)

FromHeader builds a route path from an HTTP header

func (ReadOnlyRequest) Send

func (r ReadOnlyRequest) Send(command wit.Command) error

Send sends an command through a socket, or returns an error if the socket is closed

type Request

type Request struct {
	ReadOnlyRequest

	*StatusCodeGetterSetter
	ResponseHeader http.Header
	// contains filtered or unexported fields
}

Request wraps an HTTP request

func (Request) ChangeParams

func (r Request) ChangeParams(modifier func(Params))

ChangeParams applies a modifier function to the full parameters of this request

func (Request) ContextVary

func (r Request) ContextVary(headers ...string)

ContextVary adds several headers to the Vary header, for the duration of this context

func (Request) Handle

func (r Request) Handle(o HandleOptions) (wit.Command, func())

Handle executes the appropiate plans and gathers returned commands

func (Request) HandleBody

func (r Request) HandleBody(f func(http.ResponseWriter))

HandleBody tells the controller how to handle the response body

func (Request) HandleResponse

func (r Request) HandleResponse(f func(http.ResponseWriter))

HandleResponse tells the controller how to handle the response

func (Request) Load

func (r Request) Load(dependencies ...string)

Load marks the provided dependencies as required

func (Request) MaxBytesReader

func (r Request) MaxBytesReader(rc io.ReadCloser, n int64) io.ReadCloser

MaxBytesReader limits the size of a reader

func (Request) ParamsRedirect

func (r Request) ParamsRedirect(params Params)

ParamsRedirect issues an internal redirection changing only route parameters

func (Request) ParamsURLRedirect

func (r Request) ParamsURLRedirect(statusCode int, params way.Params) error

ParamsURLRedirect issues an HTTP redirection changing only route parameters

func (Request) PartialRedirect

func (r Request) PartialRedirect(params Params, route ...string)

PartialRedirect issues an internal redirection at the current controller, starting from the current route level

func (Request) PartialURLRedirect

func (r Request) PartialURLRedirect(statusCode int, params way.Params, route ...string) error

PartialURLRedirect issues an HTTP redirection starting from the current route level

func (Request) Redirect

func (r Request) Redirect(params Params, route ...string)

Redirect issues an internal redirection at the current controller

func (Request) ServeContent

func (r Request) ServeContent(name string, modtime time.Time, content io.ReadSeeker)

ServeContent replies to the request using the content in the provided ReadSeeker

func (Request) ServeFile

func (r Request) ServeFile(name string)

ServeFile replies to the request with the contents of the named file or directory

func (Request) SetCookie

func (r Request) SetCookie(cookie *http.Cookie)

SetCookie adds a Set-Cookie header to the provided ResponseWriter's headers

func (Request) URLRedirect

func (r Request) URLRedirect(statusCode int, params way.Params, route ...string) error

URLRedirect issues an HTTP redirection

func (Request) UseCustomBody

func (r Request) UseCustomBody(reader io.Reader)

UseCustomBody tells the controller to send the provided reader as the response of this request

func (Request) UseEmptyBody

func (r Request) UseEmptyBody()

UseEmptyBody tells the controller to send an empty body as the response of this request

func (Request) Vary

func (r Request) Vary(headers ...string)

Vary adds several headers to the Vary header

type StatusCodeGetterSetter

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

StatusCodeGetterSetter holds a status code in a concurrent-safe way

func (*StatusCodeGetterSetter) SetStatusCode

func (sc *StatusCodeGetterSetter) SetStatusCode(statusCode int)

SetStatusCode sets the internal status code

func (*StatusCodeGetterSetter) StatusCode

func (sc *StatusCodeGetterSetter) StatusCode() int

StatusCode retrieves the internal status code

Jump to

Keyboard shortcuts

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