Package toxiproxy
Overview ▹
Index ▹
Variables
var ( ErrBadRequestBody = newError("bad request body", http.StatusBadRequest) ErrMissingField = newError("missing required field", http.StatusBadRequest) ErrProxyNotFound = newError("proxy not found", http.StatusNotFound) ErrProxyAlreadyExists = newError("proxy already exists", http.StatusConflict) ErrInvalidStream = newError("stream was invalid, can be either upstream or downstream", http.StatusBadRequest) ErrInvalidToxicType = newError("invalid toxic type", http.StatusBadRequest) ErrToxicAlreadyExists = newError("toxic already exists", http.StatusConflict) ErrToxicNotFound = newError("toxic not found", http.StatusNotFound) )
var ErrProxyAlreadyStarted = errors.New("Proxy already started")
var Version = "git"
type ApiError ¶
type ApiError struct { Message string `json:"error"` StatusCode int `json:"status"` }
func (*ApiError) Error ¶
func (e *ApiError) Error() string
type ApiServer ¶
type ApiServer struct { Collection *ProxyCollection }
func NewServer ¶
func NewServer() *ApiServer
func (*ApiServer) Listen ¶
func (server *ApiServer) Listen(host string, port string)
func (*ApiServer) Populate ¶
func (server *ApiServer) Populate(response http.ResponseWriter, request *http.Request)
func (*ApiServer) PopulateConfig ¶
func (server *ApiServer) PopulateConfig(filename string)
func (*ApiServer) ProxyCreate ¶
func (server *ApiServer) ProxyCreate(response http.ResponseWriter, request *http.Request)
func (*ApiServer) ProxyDelete ¶
func (server *ApiServer) ProxyDelete(response http.ResponseWriter, request *http.Request)
func (*ApiServer) ProxyIndex ¶
func (server *ApiServer) ProxyIndex(response http.ResponseWriter, request *http.Request)
func (*ApiServer) ProxyShow ¶
func (server *ApiServer) ProxyShow(response http.ResponseWriter, request *http.Request)
func (*ApiServer) ProxyUpdate ¶
func (server *ApiServer) ProxyUpdate(response http.ResponseWriter, request *http.Request)
func (*ApiServer) ResetState ¶
func (server *ApiServer) ResetState(response http.ResponseWriter, request *http.Request)
func (*ApiServer) ToxicCreate ¶
func (server *ApiServer) ToxicCreate(response http.ResponseWriter, request *http.Request)
func (*ApiServer) ToxicDelete ¶
func (server *ApiServer) ToxicDelete(response http.ResponseWriter, request *http.Request)
func (*ApiServer) ToxicIndex ¶
func (server *ApiServer) ToxicIndex(response http.ResponseWriter, request *http.Request)
func (*ApiServer) ToxicShow ¶
func (server *ApiServer) ToxicShow(response http.ResponseWriter, request *http.Request)
func (*ApiServer) ToxicUpdate ¶
func (server *ApiServer) ToxicUpdate(response http.ResponseWriter, request *http.Request)
func (*ApiServer) Version ¶
func (server *ApiServer) Version(response http.ResponseWriter, request *http.Request)
type ConnectionList ¶
type ConnectionList struct {
// contains filtered or unexported fields
}
func (*ConnectionList) Lock ¶
func (c *ConnectionList) Lock()
func (*ConnectionList) Unlock ¶
func (c *ConnectionList) Unlock()
type Proxy ¶
Proxy represents the proxy in its entirity with all its links. The main responsibility of Proxy is to accept new client and create Links between the client and upstream.
Client <-> toxiproxy <-> Upstream
type Proxy struct {
sync.Mutex
Name string `json:"name"`
Listen string `json:"listen"`
Upstream string `json:"upstream"`
Enabled bool `json:"enabled"`
Toxics *ToxicCollection `json:"-"`
// contains filtered or unexported fields
}
func NewProxy ¶
func NewProxy() *Proxy
func (*Proxy) RemoveConnection ¶
func (proxy *Proxy) RemoveConnection(name string)
func (*Proxy) Start ¶
func (proxy *Proxy) Start() error
func (*Proxy) Stop ¶
func (proxy *Proxy) Stop()
func (*Proxy) Update ¶
func (proxy *Proxy) Update(input *Proxy) error
type ProxyCollection ¶
ProxyCollection is a collection of proxies. It's the interface for anything to add and remove proxies from the toxiproxy instance. It's responsibilty is to maintain the integrity of the proxy set, by guarding for things such as duplicate names.
type ProxyCollection struct {
sync.RWMutex
// contains filtered or unexported fields
}
func NewProxyCollection ¶
func NewProxyCollection() *ProxyCollection
func (*ProxyCollection) Add ¶
func (collection *ProxyCollection) Add(proxy *Proxy, start bool) error
func (*ProxyCollection) AddOrReplace ¶
func (collection *ProxyCollection) AddOrReplace(proxy *Proxy, start bool) error
func (*ProxyCollection) Clear ¶
func (collection *ProxyCollection) Clear() error
func (*ProxyCollection) Get ¶
func (collection *ProxyCollection) Get(name string) (*Proxy, error)
func (*ProxyCollection) PopulateJson ¶
func (collection *ProxyCollection) PopulateJson(data io.Reader) ([]*Proxy, error)
func (*ProxyCollection) Proxies ¶
func (collection *ProxyCollection) Proxies() map[string]*Proxy
func (*ProxyCollection) Remove ¶
func (collection *ProxyCollection) Remove(name string) error
type ToxicCollection ¶
ToxicCollection contains a list of toxics that are chained together. Each proxy has its own collection. A hidden noop toxic is always maintained at the beginning of each chain so toxics have a method of pausing incoming data (by interrupting the preceding toxic).
type ToxicCollection struct {
sync.Mutex
// contains filtered or unexported fields
}
func NewToxicCollection ¶
func NewToxicCollection(proxy *Proxy) *ToxicCollection
func (*ToxicCollection) AddToxicJson ¶
func (c *ToxicCollection) AddToxicJson(data io.Reader) (*toxics.ToxicWrapper, error)
func (*ToxicCollection) GetToxic ¶
func (c *ToxicCollection) GetToxic(name string) *toxics.ToxicWrapper
func (*ToxicCollection) GetToxicArray ¶
func (c *ToxicCollection) GetToxicArray() []toxics.Toxic
func (*ToxicCollection) RemoveLink ¶
func (c *ToxicCollection) RemoveLink(name string)
func (*ToxicCollection) RemoveToxic ¶
func (c *ToxicCollection) RemoveToxic(name string) error
func (*ToxicCollection) ResetToxics ¶
func (c *ToxicCollection) ResetToxics()
func (*ToxicCollection) StartLink ¶
func (c *ToxicCollection) StartLink(name string, input io.Reader, output io.WriteCloser, direction stream.Direction)
func (*ToxicCollection) UpdateToxicJson ¶
func (c *ToxicCollection) UpdateToxicJson(name string, data io.Reader) (*toxics.ToxicWrapper, error)
type ToxicLink ¶
ToxicLinks are single direction pipelines that connects an input and output via a chain of toxics. The chain always starts with a NoopToxic, and toxics are added and removed as they are enabled/disabled. New toxics are always added to the end of the chain.
NoopToxic LatencyToxic v v
Input > ToxicStub > ToxicStub > Output
type ToxicLink struct {
// contains filtered or unexported fields
}
func NewToxicLink ¶
func NewToxicLink(proxy *Proxy, collection *ToxicCollection, direction stream.Direction) *ToxicLink
func (*ToxicLink) AddToxic ¶
func (link *ToxicLink) AddToxic(toxic *toxics.ToxicWrapper)
Add a toxic to the end of the chain.
func (*ToxicLink) RemoveToxic ¶
func (link *ToxicLink) RemoveToxic(toxic *toxics.ToxicWrapper)
Remove an existing toxic from the chain.
func (*ToxicLink) Start ¶
func (link *ToxicLink) Start(name string, source io.Reader, dest io.WriteCloser)
Start the link with the specified toxics
func (*ToxicLink) UpdateToxic ¶
func (link *ToxicLink) UpdateToxic(toxic *toxics.ToxicWrapper)
Update an existing toxic in the chain.