Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Group = reflect.TypeOf(PropertyGroup{})
Group PropertyGroup type variable.
Functions ¶
This section is empty.
Types ¶
type CustomRule ¶
type CustomRule struct {
// contains filtered or unexported fields
}
CustomRule a rule type that allows users to define their own rule.
func NewCustomRule ¶
func NewCustomRule(n string, typ Type, v func(interface{}) (bool, string)) CustomRule
NewCustomRule creates a new custom rule that can be applied to properties.
func (*CustomRule) SetDescription ¶
func (cr *CustomRule) SetDescription(desc string)
SetDescription sets the rules description.
type EnumRule ¶
type EnumRule struct {
// contains filtered or unexported fields
}
EnumRule checks to see if the property value is within a set of valid values.
func NewEnumRule ¶
NewEnumRule checks to see if all members provided are the same type, if so, it will return a valid EnumRule. if not, it will return a blank rule and a error. type is inferred by checking the first member of the array.
type Middleware ¶
type Middleware struct {
// contains filtered or unexported fields
}
Middleware represents a middleware function that uses http.Handler
func NewMiddleware ¶
NewMiddleware returns a new middleware with the name and handler provided.
func (*Middleware) SetDescription ¶
func (m *Middleware) SetDescription(desc string)
SetDescription set the description of the middleware
type MyAPI ¶
type MyAPI struct { Name string Routes []Route Port string // contains filtered or unexported fields }
MyAPI ...
func (*MyAPI) StartServer ¶
StartServer starts the server using the port and managed routers.
func (*MyAPI) StartTestServer ¶
StartTestServer starts the server using httptest.NewServer() instead of http.ListenAndServe for testing purposes.
func (*MyAPI) UseMiddleware ¶
func (m *MyAPI) UseMiddleware(mw Middleware)
UseMiddleware applies the middleware provided to the router. this middleware is used for all routes.
func (*MyAPI) UseRoute ¶
UseRoute applies an individual route to the api that is not part of any subrouter.
func (*MyAPI) UseSubrouter ¶
UseSubrouter applies a SubRouter to the api.
type ObjectProperty ¶
type ObjectProperty struct { Name string // contains filtered or unexported fields }
ObjectProperty represents a property that would be an object type in json instead of a basic type. contains a group of properties that will validate the items contained in the json object.
func NewObjectProperty ¶
func NewObjectProperty(name string, slice bool) ObjectProperty
NewObjectProperty creates a new Object Property with the name provided and sets the slice
func (*ObjectProperty) UsePropertyGroup ¶
func (o *ObjectProperty) UsePropertyGroup(pg PropertyGroup)
UsePropertyGroup sets the property group on the object.
type Property ¶
type Property struct { Name string // contains filtered or unexported fields }
Property represents a single property in a request body.
func NewProperty ¶
NewProperty creates a property with a blank rule set.
type PropertyGroup ¶
type PropertyGroup struct {
// contains filtered or unexported fields
}
PropertyGroup wrapper used to be sure property names are unique when applied to a route.
func NewPropertyGroup ¶
func NewPropertyGroup() PropertyGroup
NewPropertyGroup creates a PropertyGroup with no properties.
func PropsFromType ¶
func PropsFromType(t reflect.Type) PropertyGroup
PropsFromType receives a reflect.Type of a struct and returns a propertygroup based of the field name and types of the struct useful for creating propertygroups that dont need any specific rules applied to them. will panic if the provided type's kind is not a struct.
func (*PropertyGroup) AddProperties ¶
func (pg *PropertyGroup) AddProperties(props ...Props) error
AddProperties attempts to add properties to PropertyGroup. It will throw an error if any Properties have conflicting names or aliases.
type Props ¶
type Props interface {
// contains filtered or unexported methods
}
Props the interface that should represent a single property in a json object. currently Property and Object Property implement it.
type RegexRule ¶
type RegexRule struct {
// contains filtered or unexported fields
}
RegexRule checks to see if the propety value of a property matches the provided regex string.
func NewRegexRule ¶
NewRegexRule accepts a string, confirms it's a valid regex pattern, and returns a rule if the pattern is valid. If it is not, it will return a blank rule and an error noting that the regex is invalid.
type Route ¶
type Route struct {
// contains filtered or unexported fields
}
Route describes a single route in the API.
func NewRoute ¶
func NewRoute(path string, Handler http.HandlerFunc, method ...string) Route
NewRoute takes in all neccesay parts of a route: path method and handler function. other fields can be set via other functions.
func (*Route) AddProperty ¶
AddProperty adds all provided properties to the route. this will throw an error if a property name is duplicated.
func (*Route) AddPropertyGroup ¶
func (r *Route) AddPropertyGroup(pg PropertyGroup)
AddPropertyGroup adds an entire propertygroup to the route properties note: this will replace any current properties on the route.
func (*Route) SetDescription ¶
SetDescription sets the description field on the Route.
type Rule ¶
type Rule interface {
// contains filtered or unexported methods
}
Rule Interface that defines the common interfaced that should be used when implementing a rule type all implemented rules can assume that the provided value is already an appropriate type, because the value will have been type checked before and invalid ones will not make it to the rule. NOTE: rules cannot be applied to the Object Property Type.
type SubRouter ¶
type SubRouter struct {
// contains filtered or unexported fields
}
SubRouter a grouping of routes. all routes added to the subrouter will be prefixed with the prefix string.
func NewSubRouter ¶
NewSubRouter returns an empty subrouter with the provided prefix
func (*SubRouter) UseMiddleware ¶
func (sr *SubRouter) UseMiddleware(mw Middleware)
UseMiddleware applies the middleware to the provided