killgrave

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2019 License: MIT Imports: 15 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 ReadConfigFile added in v0.3.3

func ReadConfigFile(path string, config *Config) error

ReadConfigFile unmarshal content of config file to Config struct

Types

type Config added in v0.3.3

type Config struct {
	ImpostersPath string     `yaml:"imposters_path"`
	Port          int        `yaml:"port"`
	Host          string     `yaml:"host"`
	CORS          ConfigCORS `yaml:"cors"`
}

Config representation of config file yaml

type ConfigCORS added in v0.3.3

type ConfigCORS struct {
	Methods          []string `yaml:"methods"`
	Headers          []string `yaml:"headers"`
	Origins          []string `yaml:"origins"`
	ExposedHeaders   []string `yaml:"exposed_headers"`
	AllowCredentials bool     `yaml:"allow_credentials"`
}

ConfigCORS representation of section CORS of the yaml

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

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"`
	Headers  *map[string]string `json:"headers"`
}

Response represent the structure of real response

type Server

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

Server definition of mock server

func NewServer

func NewServer(p string, r *mux.Router) *Server

NewServer initialize the mock server

func (*Server) AccessControl added in v0.3.2

func (s *Server) AccessControl(config ConfigCORS) (h []handlers.CORSOption)

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

func (*Server) Build

func (s *Server) Build() error

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

Jump to

Keyboard shortcuts

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