mocker

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateRoutes

func GenerateRoutes(path string, r *gin.Engine) error

GenerateRoutes generates the routes and applies them to the r gin.Engine

Types

type All

type All struct {
	Endpoints []Endpoint `yaml:"endpoints"`
}

All stores all the information of the configuration file

type DeleteEndpoint

type DeleteEndpoint struct {
	MethodEndpoint `yaml:",inline"`
}

DeleteEndpoint implements the EndpointGenerator interface

func (DeleteEndpoint) Generate

func (e DeleteEndpoint) Generate(path string, r *gin.Engine)

Generate generates the endpoint

type Endpoint

type Endpoint struct {
	Path    string           `yaml:"path"`
	Get     *GetEndpoint     `yaml:"get"`
	Post    *PostEndpoint    `yaml:"post"`
	Put     *PutEndpoint     `yaml:"put"`
	Patch   *PatchEndpoint   `yaml:"patch"`
	Delete  *DeleteEndpoint  `yaml:"delete"`
	Head    *HeadEndpoint    `yaml:"head"`
	Options *OptionsEndpoint `yaml:"options"`

	All []EndpointGenerator `yaml:"-"`
}

Endpoint is a simple endpoint struct used to parse the configuration file

func (*Endpoint) Compute

func (e *Endpoint) Compute()

Compute checks every possible endpoint to generate a slice of EndpointGenerator

type EndpointGenerator

type EndpointGenerator interface {
	Generate(string, *gin.Engine)
}

EndpointGenerator is an interface that allows to generate endpoints

type GetEndpoint

type GetEndpoint struct {
	MethodEndpoint `yaml:",inline"`
}

GetEndpoint implements the EndpointGenerator interface

func (GetEndpoint) Generate

func (e GetEndpoint) Generate(path string, r *gin.Engine)

Generate generates the endpoint

type HeadEndpoint

type HeadEndpoint struct {
	MethodEndpoint `yaml:",inline"`
}

HeadEndpoint implements the EndpointGenerator interface

func (HeadEndpoint) Generate

func (e HeadEndpoint) Generate(path string, r *gin.Engine)

Generate generates the endpoint

type Header struct {
	Name  string `yaml:"name"`
	Value string `yaml:"value"`
}

Header is a simple header struct used to parse the configuration file

type MethodEndpoint

type MethodEndpoint struct {
	Preset    string      `yaml:"preset"` // random, ratio
	Responses []*Response `yaml:"responses"`
	Headers   []string    `yaml:"headers"`
}

MethodEndpoint represents a single endpoint

func (*MethodEndpoint) CalcRatios

func (e *MethodEndpoint) CalcRatios()

CalcRatios computes the ratios for every response that doesn't have one

func (MethodEndpoint) PickResponse

func (e MethodEndpoint) PickResponse() *Response

PickResponse picks a random response according to the ratio defined in the responses

func (MethodEndpoint) ToHandler

func (e MethodEndpoint) ToHandler() func(c *gin.Context)

ToHandler generates a handler to apply on the router

type OptionsEndpoint

type OptionsEndpoint struct {
	MethodEndpoint `yaml:",inline"`
}

OptionsEndpoint implements the EndpointGenerator interface

func (OptionsEndpoint) Generate

func (e OptionsEndpoint) Generate(path string, r *gin.Engine)

Generate generates the endpoint

type PatchEndpoint

type PatchEndpoint struct {
	MethodEndpoint `yaml:",inline"`
}

PatchEndpoint implements the EndpointGenerator interface

func (PatchEndpoint) Generate

func (e PatchEndpoint) Generate(path string, r *gin.Engine)

Generate generates the endpoint

type PostEndpoint

type PostEndpoint struct {
	MethodEndpoint `yaml:",inline"`
}

PostEndpoint implements the EndpointGenerator interface

func (PostEndpoint) Generate

func (e PostEndpoint) Generate(path string, r *gin.Engine)

Generate generates the endpoint

type PutEndpoint

type PutEndpoint struct {
	MethodEndpoint `yaml:",inline"`
}

PutEndpoint implements the EndpointGenerator interface

func (PutEndpoint) Generate

func (e PutEndpoint) Generate(path string, r *gin.Engine)

Generate generates the endpoint

type Response

type Response struct {
	Code    int      `yaml:"code"`
	Body    string   `yaml:"body"`
	Headers []Header `yaml:"headers"`
	Preset  string   `yaml:"preset"`
	Ratio   int      `yaml:"ratio"`
}

Response is a simple response struct used to parse the configuration file

Jump to

Keyboard shortcuts

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