server

package
v0.0.0-...-50ea438 Latest Latest
Warning

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

Go to latest
Published: May 19, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyTemplateFile

func ApplyTemplateFile(name, filename string, data interface{}) (string, error)

func ApplyTemplateText

func ApplyTemplateText(name, text string, data interface{}) (string, error)

func CreateScaffold

func CreateScaffold(dirname string) error

func StartHttpServer

func StartHttpServer(addr string, config *Config, cors, tls bool, cert, key string, errorNoMatch bool, reporter Reporter) error

func TryConversation

func TryConversation(request *Request, command *Command, response *Response, reporter Reporter, w http.ResponseWriter, r *http.Request)

func TryRunRobots

func TryRunRobots(upgrade *Upgrade, robots *Robots, reporter Reporter, w http.ResponseWriter, r *http.Request)

Types

type CliReporter

type CliReporter struct {
	cli.Ui
}

func (CliReporter) Error

func (r CliReporter) Error(s string)

func (CliReporter) Errorf

func (r CliReporter) Errorf(format string, a ...interface{})

func (CliReporter) Info

func (r CliReporter) Info(s string)

func (CliReporter) Infof

func (r CliReporter) Infof(format string, a ...interface{})

func (CliReporter) IsEnabled

func (r CliReporter) IsEnabled() bool

func (CliReporter) Warn

func (r CliReporter) Warn(s string)

func (CliReporter) Warnf

func (r CliReporter) Warnf(format string, a ...interface{})

type Command

type Command struct {
	Env  []string `yaml:",omitempty"`
	Path string   `yaml:",omitempty"`
	Args []string `yaml:",omitempty"`
}

func (*Command) Execute

func (c *Command) Execute(conversation *Conversation) error

type CommandInConversation

type CommandInConversation struct {
	Env    []string
	Path   string
	Args   []string
	Dir    string
	Stdout string
	Stderr string
}

func (*CommandInConversation) ParseStderrAsJson

func (c *CommandInConversation) ParseStderrAsJson() interface{}

func (*CommandInConversation) ParseStderrAsYaml

func (c *CommandInConversation) ParseStderrAsYaml() interface{}

func (*CommandInConversation) ParseStdoutAsJson

func (c *CommandInConversation) ParseStdoutAsJson() interface{}

func (*CommandInConversation) ParseStdoutAsYaml

func (c *CommandInConversation) ParseStdoutAsYaml() interface{}

type Config

type Config []ConfigItem

func NewConfig

func NewConfig(filename string) (*Config, error)

func (*Config) EqualTo

func (c *Config) EqualTo(other *Config) bool

func (*Config) SaveToFile

func (c *Config) SaveToFile(filename string) error

func (*Config) SelectConfigItem

func (c *Config) SelectConfigItem(method, route string, headers http.Header) (*ConfigItem, bool)

func (*Config) ToYaml

func (c *Config) ToYaml() ([]byte, error)

type ConfigItem

type ConfigItem struct {
	Request  Request  `yaml:",omitempty"`
	Upgrade  Upgrade  `yaml:",omitempty"`
	Robots   Robots   `yaml:",omitempty"`
	Command  Command  `yaml:",omitempty"`
	Response Response `yaml:",omitempty"`
}

type Conversation

type Conversation struct {
	Request RequestInConversation
	Command CommandInConversation
}

func (*Conversation) GetByIndex

func (c *Conversation) GetByIndex(values []string, index int) string

func (*Conversation) GetByKey

func (c *Conversation) GetByKey(values map[string][]string, key string) []string

func (*Conversation) JoinWith

func (c *Conversation) JoinWith(values []string, sep string) string

func (*Conversation) ReadFile

func (c *Conversation) ReadFile(filename string) string

func (*Conversation) ReadFiles

func (c *Conversation) ReadFiles(filename string) []string
type Cookie struct {
	Name  string
	Value string

	Path     string `yaml:",omitempty"`
	Domain   string `yaml:",omitempty"`
	Expires  string `yaml:",omitempty"`
	MaxAge   int    `yaml:",omitempty"`
	Secure   bool   `yaml:",omitempty"`
	HttpOnly bool   `yaml:",omitempty"`
}

type NoopReporter

type NoopReporter struct{}

func (NoopReporter) Error

func (r NoopReporter) Error(s string)

func (NoopReporter) Errorf

func (r NoopReporter) Errorf(format string, a ...interface{})

func (NoopReporter) Info

func (r NoopReporter) Info(s string)

func (NoopReporter) Infof

func (r NoopReporter) Infof(format string, a ...interface{})

func (NoopReporter) IsEnabled

func (r NoopReporter) IsEnabled() bool

func (NoopReporter) Warn

func (r NoopReporter) Warn(s string)

func (NoopReporter) Warnf

func (r NoopReporter) Warnf(format string, a ...interface{})

type Reporter

type Reporter interface {
	IsEnabled() bool

	Info(string)
	Infof(format string, a ...interface{})
	Warn(string)
	Warnf(format string, a ...interface{})
	Error(string)
	Errorf(format string, a ...interface{})
}

func NewReporter

func NewReporter(ui cli.Ui) Reporter

type Request

type Request struct {
	Method  string            `yaml:",omitempty"`
	Route   string            `yaml:",omitempty"`
	Headers map[string]string `yaml:",omitempty"`
}

func (*Request) Transform

func (r *Request) Transform(conversation *Conversation, request *http.Request) error

type RequestInConversation

type RequestInConversation struct {
	Method     string
	URL        *url.URL
	Headers    map[string][]string
	RemoteAddr string
	Body       string
	Form       map[string][]string
}

func (*RequestInConversation) ParseBodyAsJson

func (r *RequestInConversation) ParseBodyAsJson() interface{}

func (*RequestInConversation) ParseBodyAsYaml

func (r *RequestInConversation) ParseBodyAsYaml() interface{}

type Response

type Response struct {
	Status   int               `yaml:",omitempty"`
	Headers  map[string]string `yaml:",omitempty"`
	Cookies  []Cookie          `yaml:",omitempty"`
	Body     string            `yaml:",omitempty"`
	Template string            `yaml:",omitempty"`
	File     string            `yaml:",omitempty"`
}

func (*Response) Write

func (r *Response) Write(conversation *Conversation, writer http.ResponseWriter) error

type RobotFactory

type RobotFactory struct {
	Connection UpgradedConnection
}

type RobotItem

type RobotItem struct {
	Source    SourceOrSink
	Transform Transform
	Sink      SourceOrSink
}

type Robots

type Robots []RobotItem

func (*Robots) Run

func (r *Robots) Run(robotFactory *RobotFactory)

type SourceOrSink

type SourceOrSink struct {
	Type     int
	Body     string `yaml:",omitempty"`
	Template string `yaml:",omitempty"`
	File     string `yaml:",omitempty"`
}

type Transform

type Transform struct {
	Env  []string `yaml:",omitempty"`
	Path string   `yaml:",omitempty"`
	Args []string `yaml:",omitempty"`
}

type Upgrade

type Upgrade struct {
	Protocol string `yaml:",omitempty"`
}

func (*Upgrade) Execute

func (u *Upgrade) Execute(robotFactory *RobotFactory, response http.ResponseWriter, request *http.Request) error

type UpgradedConnection

type UpgradedConnection interface {
	ReadMessage() (int, []byte, error)
	WriteMessage(int, []byte) error
	Close() error
}

Jump to

Keyboard shortcuts

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