Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { ServerConfig *ServerConf `hcl:"server,block"` // contains filtered or unexported fields }
Config is the root config object that holds entire mockaroo config
func LoadConfig ¶
LoadConfig loads the given config file in path and returns a pointed to Config object if successful other wise returns a InvalidConfigFile error
type InvalidConfigFile ¶
type InvalidConfigFile struct {
// contains filtered or unexported fields
}
InvalidConfigFile error is raised when given input hcl file fails validation
func (*InvalidConfigFile) Error ¶
func (e *InvalidConfigFile) Error() string
type Mock ¶
type Mock struct { Name string `hcl:"name,label"` Request *Request `hcl:"request,block"` Response *Response `hcl:"response,block"` }
Mock matches a specific request and lays out how to generate a response to the request
type MockServer ¶
type MockServer interface { //Start starts the mock server and if the server cannot be started //returns an error Start() error }
MockServer encapsulates a full mockaroo server
func NewServer ¶
func NewServer(conf *Config) MockServer
NewServer creates a mock server with the given configuration
type Request ¶
type Request struct { Path *string `hcl:"path"` NormalizedPath string PathPrefix bool // should this path be a prefix formulated from the Path Verb *string `hcl:"verb"` Headers map[string]string `hcl:"headers,optional"` // request match headers Queries map[string]string `hcl:"queries,optional"` // query match headers }
Request encapsulates a mock request with all information to match a specific request
type RequestLog ¶
type Response ¶
type Response struct { Status int `hcl:"status,optional"` ResponseBody *string `hcl:"body"` ResponseFile *string `hcl:"file"` Headers map[string]string `hcl:"headers,optional"` Delay *Delay `hcl:"delay,block"` Template *template.Template Content []byte }
Response encapsulates a complete mock response to a mock Request
type ServerConf ¶
type ServerConf struct { ListenAddr *string `hcl:"listen_addr"` SnakeOilCertPath *string `hcl:"snake_oil_cert"` SnakeOilKeyPath *string `hcl:"snake_oil_key"` RequestLogPath *string `hcl:"request_log_path"` Mocks []*Mock `hcl:"mock,block"` Mode ServerMode }
ServerConf mockaroo server configuration
type TemplateContext ¶
type TemplateContext struct { //Method is the HTTP method for the request (GET, POST, PUT, etc.) Method *string //Protocol HTTP 1.1/2 Protocol *string //Host to which the request came Host *string //RemoteAddr from which the request came RemoteAddr *string //Headers are key value pairs from request headers Headers http.Header //Form is all the form data from the request including Query params Form url.Values //JsonBody will be non nil if the request body can be parsed as JSON JsonBody map[string]interface{} //PathVars is the path variables captured as a part of the path PathVars map[string]string //Fake contains the context to fake data from "github.com/brianvoe/gofakeit" Fake *fakeit.Faker // contains filtered or unexported fields }
func NewTemplateContext ¶
func NewTemplateContext(req *http.Request) *TemplateContext
NewTemplateContext returns a pointer to TemplateContext
func (*TemplateContext) NewUUID ¶
func (tc *TemplateContext) NewUUID() string
NewUUID generates a new pseudo random UUID seeded by the same constance value
func (*TemplateContext) PathVariable ¶
func (tc *TemplateContext) PathVariable(key string) string
func (*TemplateContext) RandomFloat ¶
func (tc *TemplateContext) RandomFloat(min, max float32) float32
RandomFloat generates a new pseudo random float32 between min and max seeded by the same constance value
func (*TemplateContext) RandomInt ¶
func (tc *TemplateContext) RandomInt(min, max int) int
RandomInt generates a new pseudo random int between min and max seeded by the same constance value