responder

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2020 License: GPL-3.0 Imports: 19 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutoResponder

type AutoResponder interface {
	//Init auto responder
	Init()
	//AddOrUpdateRule adds or updates given rule
	AddOrUpdateRule(rule *Rule)
	//FindMatchingRule gets the rule with given url pattern and http method
	FindMatchingRule(urlPattern string, method string) *Rule
	//GetRule gets the rule with given id
	GetRule(id uint64) *Rule
	//GetRules gets the rules with given url pattern and http method
	GetRules() []*Rule
	//RemoveRule removes the rule
	RemoveRule(id uint64)
	//AddOrUpdateResponse adds or updates given rule
	AddOrUpdateResponse(response *Response)
	//GetResponse gets the response with given id
	GetResponse(id uint64) *Response
	//GetResponses gets the response slice
	GetResponses() []*Response
	//RemoveResponse removes the response with given id
	RemoveResponse(id uint64)
}

AutoResponder implements an interface for autoresponder

func NewAutoResponder

func NewAutoResponder(conf *utils.Config) AutoResponder

NewAutoResponder Inits an Auto Responder

type DBAutoResponder

type DBAutoResponder struct {
	DBPath string
	// contains filtered or unexported fields
}

DBAutoResponder DB auto responder

func NewDBAutoResponder

func NewDBAutoResponder() DBAutoResponder

NewDBAutoResponder Inits a DB Auto Responder

func (*DBAutoResponder) AddOrUpdateResponse

func (ar *DBAutoResponder) AddOrUpdateResponse(response *Response)

AddOrUpdateResponse adds or updates given rule

func (*DBAutoResponder) AddOrUpdateRule

func (ar *DBAutoResponder) AddOrUpdateRule(rule *Rule)

AddOrUpdateRule adds or updates given rule

func (*DBAutoResponder) FindMatchingRule

func (ar *DBAutoResponder) FindMatchingRule(urlPattern string, method string) *Rule

FindMatchingRule gets the rule with given url pattern and http method

func (*DBAutoResponder) GetResponse

func (ar *DBAutoResponder) GetResponse(id uint64) *Response

GetResponse gets the response with given id

func (*DBAutoResponder) GetResponses

func (ar *DBAutoResponder) GetResponses() []*Response

GetResponses gets the response slice

func (*DBAutoResponder) GetRule

func (ar *DBAutoResponder) GetRule(id uint64) *Rule

GetRule gets the rule with given id

func (*DBAutoResponder) GetRules

func (ar *DBAutoResponder) GetRules() []*Rule

GetRules gets the rules with given url pattern and http method

func (*DBAutoResponder) Init

func (ar *DBAutoResponder) Init()

Init auto responder

func (*DBAutoResponder) RemoveResponse

func (ar *DBAutoResponder) RemoveResponse(id uint64)

RemoveResponse removes the response with given id

func (*DBAutoResponder) RemoveRule

func (ar *DBAutoResponder) RemoveRule(id uint64)

RemoveRule removes the rule

type FarxAutoResponder

type FarxAutoResponder struct {
	FolderPath string
	Rules      []*ruleFile
}

FarxAutoResponder File system json auto responder

func NewFarxAutoResponder

func NewFarxAutoResponder() FarxAutoResponder

NewFarxAutoResponder Inits a DB Auto Responder

func (*FarxAutoResponder) AddOrUpdateResponse

func (ar *FarxAutoResponder) AddOrUpdateResponse(response *Response)

AddOrUpdateResponse adds or updates given rule

func (*FarxAutoResponder) AddOrUpdateRule

func (ar *FarxAutoResponder) AddOrUpdateRule(rule *Rule)

AddOrUpdateRule adds or updates given rule

func (*FarxAutoResponder) FindMatchingRule

func (ar *FarxAutoResponder) FindMatchingRule(urlPattern string, method string) *Rule

FindMatchingRule gets the rule with given url pattern and http method

func (*FarxAutoResponder) GetResponse

func (ar *FarxAutoResponder) GetResponse(id uint64) *Response

GetResponse gets the response with given id

func (*FarxAutoResponder) GetResponses

func (ar *FarxAutoResponder) GetResponses() []*Response

GetResponses gets the response slice

func (*FarxAutoResponder) GetRule

func (ar *FarxAutoResponder) GetRule(id uint64) *Rule

GetRule gets the rule with given id

func (*FarxAutoResponder) GetRules

func (ar *FarxAutoResponder) GetRules() []*Rule

GetRules gets the rules with given url pattern and http method

func (*FarxAutoResponder) Init

func (ar *FarxAutoResponder) Init()

Init auto responder

func (*FarxAutoResponder) Reload

func (ar *FarxAutoResponder) Reload(farxPath string) (bool, error)

Reload updates given farx

func (*FarxAutoResponder) RemoveResponse

func (ar *FarxAutoResponder) RemoveResponse(id uint64)

RemoveResponse removes the response with given id

func (*FarxAutoResponder) RemoveRule

func (ar *FarxAutoResponder) RemoveRule(id uint64)

RemoveRule removes the rule

type FarxFileXML

type FarxFileXML struct {
	XMLName xml.Name `xml:"AutoResponder"`
	States  []*State `xml:"State"`
}

FarxFileXML Farx response auto responder xml definition

func ReadFarxFile

func ReadFarxFile(path string) (*FarxFileXML, error)

ReadFarxFile Farx file reader

type Headers

type Headers struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

Headers response headers key value

type JSONAutoResponder

type JSONAutoResponder struct {
	FolderPath string
	Rules      map[uint64]*ruleFile
	Responses  map[uint64]*responseFile
}

JSONAutoResponder File system json auto responder

func NewJSONAutoResponder

func NewJSONAutoResponder() JSONAutoResponder

NewJSONAutoResponder Inits a DB Auto Responder

func (*JSONAutoResponder) AddOrUpdateResponse

func (ar *JSONAutoResponder) AddOrUpdateResponse(response *Response)

AddOrUpdateResponse adds or updates given rule

func (*JSONAutoResponder) AddOrUpdateRule

func (ar *JSONAutoResponder) AddOrUpdateRule(rule *Rule)

AddOrUpdateRule adds or updates given rule

func (*JSONAutoResponder) FindMatchingRule

func (ar *JSONAutoResponder) FindMatchingRule(urlPattern string, method string) *Rule

FindMatchingRule gets the rule with given url pattern and http method

func (*JSONAutoResponder) GetResponse

func (ar *JSONAutoResponder) GetResponse(id uint64) *Response

GetResponse gets the response with given id

func (*JSONAutoResponder) GetResponses

func (ar *JSONAutoResponder) GetResponses() []*Response

GetResponses gets the response slice

func (*JSONAutoResponder) GetRule

func (ar *JSONAutoResponder) GetRule(id uint64) *Rule

GetRule gets the rule with given id

func (*JSONAutoResponder) GetRules

func (ar *JSONAutoResponder) GetRules() []*Rule

GetRules gets the rules with given url pattern and http method

func (*JSONAutoResponder) Init

func (ar *JSONAutoResponder) Init()

Init auto responder

func (*JSONAutoResponder) RemoveResponse

func (ar *JSONAutoResponder) RemoveResponse(id uint64)

RemoveResponse removes the response with given id

func (*JSONAutoResponder) RemoveRule

func (ar *JSONAutoResponder) RemoveRule(id uint64)

RemoveRule removes the rule

type Response

type Response struct {
	ID         uint64     `json:"id"`
	Label      string     `json:"label"`
	StatusCode int        `json:"statusCode"`
	Headers    []*Headers `json:"headers"`
	Body       string     `json:"body"`
}

Response ...

func NewResponseFromString

func NewResponseFromString(content string) *Response

NewResponseFromString parse raw string content

type ResponseRule

type ResponseRule struct {
	Match   string `xml:"Match,attr"`
	Headers string `xml:"Headers,attr"`
	Body    string `xml:"Body,attr"`
	Action  string `xml:"Action,attr"`
	Latency int    `xml:"Latency,attr"`
	Enabled bool   `xml:"Enabled,attr"`
}

ResponseRule Farx response rule xml definition

func (*ResponseRule) MapToResponse

func (xmlRule *ResponseRule) MapToResponse() *Response

MapToResponse Transforms ResponseRule to Response

func (*ResponseRule) MapToRule

func (xmlRule *ResponseRule) MapToRule() *Rule

MapToRule Transforms ResponseRule to Rule

type Rule

type Rule struct {
	ID         uint64    `json:"id"`
	URLPattern string    `json:"urlPattern"`
	MatchType  string    `json:"matchType"`
	Method     string    `json:"method"`
	ResponseID uint64    `json:"responseID"`
	Latency    int       `json:"latency"`
	IsActive   bool      `json:"isActive"`
	Response   *Response `json:"-"`
}

Rule ...

func (*Rule) Write

func (r *Rule) Write(w http.ResponseWriter, req *http.Request)

type State

type State struct {
	ResponseRules []*ResponseRule `xml:"ResponseRule"`
	Enabled       bool            `xml:"Enabled,attr"`
}

State Farx response state xml definition

Jump to

Keyboard shortcuts

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