actions

package
v0.0.0-...-9a26578 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2017 License: MIT Imports: 24 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActionList

func ActionList(arg string) []string

ActionList returns a list of built-in actions

Types

type Action

type Action interface {
	PatternHolder
	Exec(w http.ResponseWriter, r *http.Request) error
}

Action represents actions to be taken when a reuest matches a given route

func GetAction

func GetAction(arg string) (Action, error)

GetAction creates an action object based on its identifier

type DataAction

type DataAction struct {
	PatternHolder
	Size int
	Type string
	Name string
}

DataAction action represents actions which responds with random bytes of data of given size and format

func NewDataAction

func NewDataAction(size string, ext string) (*DataAction, error)

NewDataAction creates a data action with size and type

func NewDataActionFromExpr

func NewDataActionFromExpr(p string) (*DataAction, error)

NewDataActionFromExpr creates a new DataAction from an expression

func NewDataActionWithName

func NewDataActionWithName(size string, ext string, name string) (*DataAction, error)

NewDataActionWithName adds a file name to the data action

func (*DataAction) Exec

func (da *DataAction) Exec(w http.ResponseWriter, r *http.Request) error

Exec executes a data action

func (*DataAction) HasName

func (da *DataAction) HasName() bool

HasName returns true if the data action has a name

func (*DataAction) SetPattern

func (da *DataAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*DataAction) String

func (da *DataAction) String() string

type DirAction

type DirAction struct {
	PatternHolder
	Root string
	// contains filtered or unexported fields
}

DirAction represents actions which serve static files out of a given folder

func DefaultDirAction

func DefaultDirAction() (*DirAction, error)

DefaultDirAction creates a dir action which serves files from current working directory

func NewDirAction

func NewDirAction(root string) (*DirAction, error)

NewDirAction creates a new dir action which serves files from the supplied folder

func NewDirActionFromExpr

func NewDirActionFromExpr(p string) (*DirAction, error)

NewDirActionFromExpr creates a new Dir action from an expression

func (*DirAction) Exec

func (da *DirAction) Exec(w http.ResponseWriter, r *http.Request) error

Exec executes a dir action

func (*DirAction) SetPattern

func (da *DirAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*DirAction) String

func (da *DirAction) String() string

type DumpAction

type DumpAction struct {
	Root string
}

DumpAction dumps all incoming requests to a file in the supplied folder

func NewDefaultDumpAction

func NewDefaultDumpAction() (*DumpAction, error)

NewDefaultDumpAction creates a dump action with current wirk dir as root dir

func NewDumpAction

func NewDumpAction(root string) (*DumpAction, error)

NewDumpAction creates a new dump action

func NewDumpActionFromExpr

func NewDumpActionFromExpr(exp string) (*DumpAction, error)

NewDumpActionFromExpr creates a new DumpAction from an expression

func (*DumpAction) Exec

func (da *DumpAction) Exec(w http.ResponseWriter, r *http.Request) error

Exec executes a dump action

func (*DumpAction) SetPattern

func (da *DumpAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*DumpAction) String

func (da *DumpAction) String() string

type EchoAction

type EchoAction struct {
	Status int
	Type   string
	Body   []byte
}

EchoAction echoes back the request body

func NewDefaultEchoAction

func NewDefaultEchoAction() (*EchoAction, error)

NewDefaultEchoAction constructs a new echo action with status 200, contentType of the request and body of the request

func NewEchoAction

func NewEchoAction(status string, contentType string, body string) (*EchoAction, error)

NewEchoAction constructs a new echo action with status, contentType and body

func NewEchoActionFromExpr

func NewEchoActionFromExpr(exp string) (*EchoAction, error)

NewEchoActionFromExpr creates a new EchoAction from an expression

func NewEchoActionWithStatus

func NewEchoActionWithStatus(status string) (*EchoAction, error)

NewEchoActionWithStatus constructs a new echo action with status

func NewEchoActionWithStatusAndType

func NewEchoActionWithStatusAndType(status string, contentType string) (*EchoAction, error)

NewEchoActionWithStatusAndType constructs a new echo action with status, contentType

func (*EchoAction) Exec

func (ea *EchoAction) Exec(w http.ResponseWriter, r *http.Request) error

Exec executes a echo action

func (*EchoAction) SetPattern

func (ea *EchoAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*EchoAction) String

func (ea *EchoAction) String() string

type FileAction

type FileAction struct {
	PatternHolder
	Path string
}

FileAction action represents actions which responds with the contents of a file

func NewFileAction

func NewFileAction(p string) (*FileAction, error)

NewFileAction creates a new FileAction

func (*FileAction) Exec

func (fa *FileAction) Exec(w http.ResponseWriter, r *http.Request) error

Exec executes a file action

func (*FileAction) SetPattern

func (fa *FileAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*FileAction) String

func (fa *FileAction) String() string

type ForwardAction

type ForwardAction struct {
	PatternHolder
	URL string
}

ForwardAction action represents actions which forwards the request to a given url

func NewForwardAction

func NewForwardAction(s string) (*ForwardAction, error)

NewForwardAction creates a new ForwardAction

func (*ForwardAction) Exec

Exec executes a foreward action

func (*ForwardAction) SetPattern

func (fa *ForwardAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*ForwardAction) String

func (fa *ForwardAction) String() string

type ImageAction

type ImageAction struct {
	PatternHolder
	Width  int
	Height int
	Color  color.Color
	Type   string
	Name   string
}

ImageAction action represents actions which responds with an image

func DefaultImageAction

func DefaultImageAction(width string, height string) (*ImageAction, error)

DefaultImageAction creates a new image action from width and height

func NewImageAction

func NewImageAction(width string, height string, color string) (*ImageAction, error)

NewImageAction creates a new image action from width, height and color

func NewImageActionFromExpr

func NewImageActionFromExpr(p string) (*ImageAction, error)

NewImageActionFromExpr creates a new image action from an expression

func NewImageActionWithName

func NewImageActionWithName(width string, height string, color string, ext string, name string) (*ImageAction, error)

NewImageActionWithName creates a new image action from width, height, color, type and name

func NewImageActionWithType

func NewImageActionWithType(width string, height string, color string, ext string) (*ImageAction, error)

NewImageActionWithType creates a new image action from width, height, color and type

func (*ImageAction) Exec

func (ia *ImageAction) Exec(w http.ResponseWriter, r *http.Request) error

Exec executes a image action

func (*ImageAction) HasName

func (ia *ImageAction) HasName() bool

HasName returns true if the image action has a name

func (*ImageAction) SetPattern

func (ia *ImageAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*ImageAction) String

func (ia *ImageAction) String() string

type JSONAction

type JSONAction struct {
	PatternHolder
	Name string
}

JSONAction action represents actions which responds with JSON

func NewJSONActionFromExpr

func NewJSONActionFromExpr(p string) (*JSONAction, error)

NewJSONActionFromExpr creates a new json action from an expression

func (*JSONAction) Exec

func (ja *JSONAction) Exec(w http.ResponseWriter, r *http.Request) error

Exec executes a json action

func (*JSONAction) SetPattern

func (ja *JSONAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*JSONAction) String

func (ja *JSONAction) String() string

type MarkdownAction

type MarkdownAction struct {
	PatternHolder
	Path string
}

MarkdownAction action represents actions which responds with html output of markdown files

func NewMarkdownAction

func NewMarkdownAction(s string) (*MarkdownAction, error)

NewMarkdownAction creates a new MarkdownAction

func (*MarkdownAction) Exec

Exec executes a string action

func (*MarkdownAction) SetPattern

func (ma *MarkdownAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*MarkdownAction) String

func (ma *MarkdownAction) String() string

type ParseComplete

type ParseComplete func(args []string) (Action, error)

ParseComplete handlers a called after the expression parsing is complete

type PatternHolder

type PatternHolder interface {
	SetPattern(p string)
}

PatternHolder holds the matched pattern for later use

type RedirectAction

type RedirectAction struct {
	PatternHolder
	URL string
}

RedirectAction action represents actions which redirect to a given url

func NewRedirectAction

func NewRedirectAction(s string) (*RedirectAction, error)

NewRedirectAction creates a new RedirectAction

func (*RedirectAction) Exec

Exec executes a redirect action

func (*RedirectAction) SetPattern

func (ra *RedirectAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*RedirectAction) String

func (ra *RedirectAction) String() string

type ShellAction

type ShellAction struct {
	PatternHolder
	Cmd string
}

ShellAction action represents actions which responds with output of a shell command

func NewShellAction

func NewShellAction(s string) (*ShellAction, error)

NewShellAction creates a new ShellAction

func (*ShellAction) Exec

func (sa *ShellAction) Exec(w http.ResponseWriter, r *http.Request) error

Exec executes a string action

func (*ShellAction) SetPattern

func (sa *ShellAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*ShellAction) String

func (sa *ShellAction) String() string

type StringAction

type StringAction struct {
	PatternHolder
	Value string
}

StringAction action represents actions which responds with a string

func NewStringAction

func NewStringAction(s string) (*StringAction, error)

NewStringAction creates a new StringAction

func (*StringAction) Exec

Exec executes a string action

func (*StringAction) SetPattern

func (sa *StringAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*StringAction) String

func (sa *StringAction) String() string

type UploadAction

type UploadAction struct {
	PatternHolder
	Key  string
	Path string
}

UploadAction represents actions which uploads files to a given folder

func DefaultUploadAction

func DefaultUploadAction() (*UploadAction, error)

DefaultUploadAction createa an upload action with form file key as upload and path as current directory

func NewUploadAction

func NewUploadAction(uploadPath string, key string) (*UploadAction, error)

NewUploadAction creates a new UploadAction

func NewUploadActionFromExpr

func NewUploadActionFromExpr(p string) (*UploadAction, error)

NewUploadActionFromExpr creates a new Upload action from an expression

func NewUploadActionWithPath

func NewUploadActionWithPath(uploadPath string) (*UploadAction, error)

NewUploadActionWithPath creates an upload action with form file key as upload and the supplied path

func (*UploadAction) Exec

Exec executes an upload action

func (*UploadAction) SetPattern

func (ua *UploadAction) SetPattern(p string)

SetPattern sets the matched pattern in the action

func (*UploadAction) String

func (ua *UploadAction) String() string

Jump to

Keyboard shortcuts

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