http

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ImposterHandler

func ImposterHandler(imposter Imposter) http.HandlerFunc

ImposterHandler create specific handler for the received imposter

func MatcherBySchema

func MatcherBySchema(imposter Imposter) mux.MatcherFunc

MatcherBySchema check if the request matching with the schema file

func PrepareAccessControl

func PrepareAccessControl(config killgrave.ConfigCORS) (h []handlers.CORSOption)

PrepareAccessControl Return options to initialize the mock server with default access control

Types

type Imposter

type Imposter struct {
	BasePath string
	Request  Request  `json:"request"`
	Response Response `json:"response"`
}

Imposter define an imposter structure

func (*Imposter) CalculateFilePath

func (i *Imposter) CalculateFilePath(filePath string) string

CalculateFilePath calculate file path based on basePath of imposter directory

func (*Imposter) Delay

func (i *Imposter) Delay() time.Duration

Delay returns delay for response that user can specify in imposter config

type ImposterConfig added in v0.4.1

type ImposterConfig struct {
	Type     ImposterType
	FilePath string
}

ImposterConfig is used to load imposters based on which type they are

type ImposterType added in v0.4.1

type ImposterType int

ImposterType allows to know the imposter type we're dealing with

const (
	// JSONImposter allows to know when we're dealing with a JSON imposter
	JSONImposter ImposterType = iota
	// YAMLImposter allows to know when we're dealing with a YAML imposter
	YAMLImposter
)

type Proxy

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

Proxy represent reverse proxy server.

func NewProxy

func NewProxy(rawurl string, mode killgrave.ProxyMode) (*Proxy, error)

NewProxy creates new proxy server.

func (*Proxy) Handler

func (p *Proxy) Handler() http.HandlerFunc

Handler returns handler that sends request to another server.

type Request

type Request struct {
	Method     string             `json:"method"`
	Endpoint   string             `json:"endpoint"`
	SchemaFile *string            `json:"schemaFile"`
	Params     *map[string]string `json:"params"`
	Headers    *map[string]string `json:"headers"`
}

Request represent the structure of real request

type Response

type Response struct {
	Status   int                `json:"status"`
	Body     string             `json:"body"`
	BodyFile *string            `json:"bodyFile" yaml:"bodyFile"`
	Headers  *map[string]string `json:"headers"`
	Delay    ResponseDelay      `json:"delay" yaml:"delay"`
}

Response represent the structure of real response

type ResponseDelay

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

ResponseDelay represent time delay before server responds.

func (*ResponseDelay) Delay

func (d *ResponseDelay) Delay() time.Duration

Delay return random time.Duration with respect to specified time range.

func (*ResponseDelay) UnmarshalJSON

func (d *ResponseDelay) UnmarshalJSON(data []byte) error

UnmarshalJSON of json.Unmarshaler interface. Input should be string, consisting of substring that can be parsed by time.ParseDuration, or two similar substrings seperated by ":".

func (*ResponseDelay) UnmarshalYAML added in v0.4.1

func (d *ResponseDelay) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML of yaml.Unmarshaler interface. Input should be string, consisting of substring that can be parsed by time.ParseDuration, or two similar substrings seperated by ":".

type Server

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

Server definition of mock server

func NewServer

func NewServer(p string, r *mux.Router, httpServer *http.Server, proxyServer *Proxy, secure bool) Server

NewServer initialize the mock server

func (*Server) Build

func (s *Server) Build() error

Build read all the files on the impostersPath and add different handlers for each imposter

func (*Server) Run

func (s *Server) Run()

Run run launch a previous configured http server if any error happens while the starting process application will be crashed

func (*Server) Shutdown

func (s *Server) Shutdown() error

Shutdown shutdown the current http server

type ServerOpt

type ServerOpt func(s *Server)

ServerOpt function that allow modify the current server

Jump to

Keyboard shortcuts

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