Documentation
¶
Index ¶
- func GenerateRoutes(path string, r *gin.Engine) error
- type BodyValidator
- type DeleteEndpoint
- type Dump
- type Endpoint
- type EndpointGenerator
- type EndpointMethod
- type GetEndpoint
- type HeadEndpoint
- type HeadersValidator
- type MockConf
- type NoRouteConf
- type OptionsEndpoint
- type PatchEndpoint
- type PostEndpoint
- type PutEndpoint
- type RequestValidator
- type Response
- type Responses
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BodyValidator ¶ added in v1.1.2
type BodyValidator struct {
Contains string `yaml:"contains"`
}
BodyValidator holds the values to validate an incoming request's body.
func (BodyValidator) Validate ¶ added in v1.1.2
func (bv BodyValidator) Validate(body []byte) error
Validate will validate that the incoming body matches the expectations of the body validator.
type DeleteEndpoint ¶
type DeleteEndpoint struct {
EndpointMethod `yaml:",inline"`
}
DeleteEndpoint implements the EndpointGenerator interface.
type Dump ¶ added in v1.1.2
type Dump []string
Dump is a type alias
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 represents a single endpoint.
type EndpointGenerator ¶
EndpointGenerator is a simple interface.
type EndpointMethod ¶ added in v1.1.2
type EndpointMethod struct { Echo bool `yaml:"echo"` Dump Dump `yaml:"dump"` Validate RequestValidator `yaml:"validate"` Responses Responses `yaml:"responses"` }
EndpointMethod represents a single method associated to a parent endpoint.
func (EndpointMethod) Info ¶ added in v1.1.2
func (e EndpointMethod) Info(last bool) string
Info returns the string representing the information.
func (EndpointMethod) ToHandler ¶ added in v1.1.2
func (e EndpointMethod) ToHandler() func(c *gin.Context)
ToHandler generates a handler to apply on the router.
type GetEndpoint ¶
type GetEndpoint struct {
EndpointMethod `yaml:",inline"`
}
GetEndpoint implements the EndpointGenerator interface.
type HeadEndpoint ¶
type HeadEndpoint struct {
EndpointMethod `yaml:",inline"`
}
HeadEndpoint implements the EndpointGenerator interface.
type HeadersValidator ¶ added in v1.1.2
type HeadersValidator struct { Present []string `yaml:"present"` Absent []string `yaml:"absent"` Match map[string]string `yaml:"match"` }
HeadersValidator holds the values to validate the headers of an incoming request.
type MockConf ¶ added in v1.1.2
type MockConf struct { Endpoints []Endpoint `yaml:"endpoints"` NoRoute *NoRouteConf `yaml:"noroute"` }
MockConf contains all the endpoints and is used for parsing.
type NoRouteConf ¶ added in v1.1.2
type NoRouteConf struct { Dump Dump `yaml:"dump"` Echo bool `yaml:"echo"` Code *int `yaml:"code"` Body *string `yaml:"body"` }
NoRouteConf defines the behavior when no route is found in the mock. Defaults to a standard 404 response.
func (NoRouteConf) Handle ¶ added in v1.1.2
func (nc NoRouteConf) Handle(r *gin.Engine)
Handle will add a special route to customize the 404 behavior.
type OptionsEndpoint ¶
type OptionsEndpoint struct {
EndpointMethod `yaml:",inline"`
}
OptionsEndpoint implements the EndpointGenerator interface.
type PatchEndpoint ¶
type PatchEndpoint struct {
EndpointMethod `yaml:",inline"`
}
PatchEndpoint implements the EndpointGenerator interface.
type PostEndpoint ¶
type PostEndpoint struct {
EndpointMethod `yaml:",inline"`
}
PostEndpoint implements the EndpointGenerator interface.
type PutEndpoint ¶
type PutEndpoint struct {
EndpointMethod `yaml:",inline"`
}
PutEndpoint implements the EndpointGenerator interface.
type RequestValidator ¶ added in v1.1.2
type RequestValidator struct { Headers HeadersValidator `yaml:"headers"` Body BodyValidator `yaml:"body"` }
RequestValidator wraps a header validator and a body validator.