Documentation ¶
Index ¶
- Variables
- func NewErrors(errors []error) error
- func ValidMod(mod ModifierType) bool
- type APIContext
- func (r *APIContext) Filter(opts QueryOptions, obj interface{}) interface{}
- func (r *APIContext) FilterList(opts QueryOptions, obj []map[string]interface{}) []map[string]interface{}
- func (r *APIContext) FilterObject(opts QueryOptions, obj map[string]interface{}) map[string]interface{}
- func (r *APIContext) WriteResponse(code int, obj interface{})
- type APIVersion
- type AccessControl
- type Action
- type ActionHandler
- type Collection
- type Condition
- type ErrorHandler
- type Field
- type Filter
- type Formatter
- type GenericCollection
- type ListOpts
- type Mapper
- type Mappers
- type MappersFactory
- type ModifierType
- type Namespaced
- type Pagination
- type QueryCondition
- type QueryConditionType
- type QueryFilter
- type QueryOptions
- type RawResource
- type ReferenceValidator
- type RequestHandler
- type Resource
- type ResourceCollection
- type ResponseWriter
- type Schema
- type SchemaCollection
- type SchemaInitFunc
- type Schemas
- func (s *Schemas) AddMapper(version *APIVersion, schemaID string, mapper Mapper) *Schemas
- func (s *Schemas) AddMapperForType(version *APIVersion, obj interface{}, mapper ...Mapper) *Schemas
- func (s *Schemas) AddSchema(schema *Schema) *Schemas
- func (s *Schemas) AddSchemas(schema *Schemas) *Schemas
- func (s *Schemas) Err() error
- func (s *Schemas) Import(version *APIVersion, obj interface{}, externalOverrides ...interface{}) (*Schema, error)
- func (s *Schemas) Init(initFunc SchemaInitFunc) *Schemas
- func (s *Schemas) MustCustomizeType(version *APIVersion, obj interface{}, f func(*Schema)) *Schemas
- func (s *Schemas) MustImport(version *APIVersion, obj interface{}, externalOverrides ...interface{}) *Schemas
- func (s *Schemas) MustImportAndCustomize(version *APIVersion, obj interface{}, f func(*Schema), ...) *Schemas
- func (s *Schemas) Schema(version *APIVersion, name string) *Schema
- func (s *Schemas) Schemas() []*Schema
- func (s *Schemas) SchemasForVersion(version APIVersion) map[string]*Schema
- func (s *Schemas) SubContext(subContext string) *Schema
- func (s *Schemas) SubContextSchemas() map[string]*Schema
- func (s *Schemas) Versions() []APIVersion
- type Sort
- type SortOrder
- type Store
- type SubContextAttributeProvider
- type TypeScope
- type URLBuilder
- type Validator
- type ValuesMap
Constants ¶
This section is empty.
Variables ¶
View Source
var ( CondEQ = QueryConditionType{ModifierEQ, 1} CondNE = QueryConditionType{ModifierNE, 1} CondNull = QueryConditionType{ModifierNull, 0} CondNotNull = QueryConditionType{ModifierNotNull, 0} CondIn = QueryConditionType{ModifierIn, -1} CondNotIn = QueryConditionType{ModifierNotIn, -1} CondOr = QueryConditionType{ModifierType("or"), 1} CondAnd = QueryConditionType{ModifierType("and"), 1} )
View Source
var ( ASC = SortOrder("asc") DESC = SortOrder("desc") )
Functions ¶
func ValidMod ¶
func ValidMod(mod ModifierType) bool
Types ¶
type APIContext ¶
type APIContext struct { Action string ID string Type string Link string Method string Schema *Schema Schemas *Schemas Version *APIVersion ResponseFormat string ReferenceValidator ReferenceValidator ResponseWriter ResponseWriter QueryFilter QueryFilter SubContextAttributeProvider SubContextAttributeProvider //QueryOptions *QueryOptions URLBuilder URLBuilder AccessControl AccessControl SubContext map[string]string Request *http.Request Response http.ResponseWriter }
func (*APIContext) Filter ¶
func (r *APIContext) Filter(opts QueryOptions, obj interface{}) interface{}
func (*APIContext) FilterList ¶
func (r *APIContext) FilterList(opts QueryOptions, obj []map[string]interface{}) []map[string]interface{}
func (*APIContext) FilterObject ¶
func (r *APIContext) FilterObject(opts QueryOptions, obj map[string]interface{}) map[string]interface{}
func (*APIContext) WriteResponse ¶
func (r *APIContext) WriteResponse(code int, obj interface{})
type APIVersion ¶
type APIVersion struct { Group string `json:"group,omitempty"` Version string `json:"version,omitempty"` Path string `json:"path,omitempty"` SubContexts map[string]bool `json:"subContext,omitempty"` }
func (*APIVersion) Equals ¶
func (v *APIVersion) Equals(other *APIVersion) bool
type AccessControl ¶
type ActionHandler ¶
type ActionHandler func(actionName string, action *Action, request *APIContext) error
type Collection ¶
type Collection struct { Type string `json:"type,omitempty"` Links map[string]string `json:"links"` CreateTypes map[string]string `json:"createTypes,omitempty"` Actions map[string]string `json:"actions"` Pagination *Pagination `json:"pagination,omitempty"` Sort *Sort `json:"sort,omitempty"` Filters map[string][]Condition `json:"filters,omitempty"` ResourceType string `json:"resourceType"` }
type Condition ¶
type Condition struct { Modifier ModifierType `json:"modifier,omitempty"` Value interface{} `json:"value,omitempty"` }
type ErrorHandler ¶
type ErrorHandler func(request *APIContext, err error)
type Field ¶
type Field struct { Type string `json:"type,omitempty"` Default interface{} `json:"default,omitempty"` Nullable bool `json:"nullable,omitempty"` Create bool `json:"create,omitempty"` WriteOnly bool `json:"writeOnly,omitempty"` Required bool `json:"required,omitempty"` Update bool `json:"update,omitempty"` MinLength *int64 `json:"minLength,omitempty"` MaxLength *int64 `json:"maxLength,omitempty"` Min *int64 `json:"min,omitempty"` Max *int64 `json:"max,omitempty"` Options []string `json:"options,omitempty"` ValidChars string `json:"validChars,omitempty"` InvalidChars string `json:"invalidChars,omitempty"` Description string `json:"description,omitempty"` CodeName string `json:"-"` }
type Filter ¶
type Filter struct {
Modifiers []ModifierType `json:"modifiers,omitempty"`
}
type Formatter ¶
type Formatter func(request *APIContext, resource *RawResource)
type GenericCollection ¶
type GenericCollection struct { Collection Data []interface{} `json:"data"` }
type MappersFactory ¶
type MappersFactory func() []Mapper
type ModifierType ¶
type ModifierType string
var ( ModifierEQ ModifierType = "eq" ModifierNE ModifierType = "ne" ModifierNull ModifierType = "null" ModifierNotNull ModifierType = "notnull" ModifierIn ModifierType = "in" ModifierNotIn ModifierType = "notin" )
type Namespaced ¶
type Namespaced struct{}
type Pagination ¶
type Pagination struct { Marker string `json:"marker,omitempty"` First string `json:"first,omitempty"` Previous string `json:"previous,omitempty"` Next string `json:"next,omitempty"` Last string `json:"last,omitempty"` Limit *int64 `json:"limit,omitempty"` Total *int64 `json:"total,omitempty"` Partial bool `json:"partial,omitempty"` }
type QueryCondition ¶
type QueryCondition struct { Field string Value string Values map[string]bool // contains filtered or unexported fields }
func NewConditionFromString ¶
func NewConditionFromString(field string, mod ModifierType, values ...string) *QueryCondition
func (*QueryCondition) ToCondition ¶
func (q *QueryCondition) ToCondition() Condition
func (*QueryCondition) Valid ¶
func (q *QueryCondition) Valid(data map[string]interface{}) bool
type QueryConditionType ¶
type QueryConditionType struct { Name ModifierType Args int }
type QueryFilter ¶
type QueryFilter func(opts QueryOptions, data []map[string]interface{}) []map[string]interface{}
type QueryOptions ¶
type QueryOptions struct { Sort Sort Pagination *Pagination Conditions []*QueryCondition Options map[string]string }
type RawResource ¶
type RawResource struct { ID string `json:"id,omitempty" yaml:"id,omitempty"` Type string `json:"type,omitempty" yaml:"type,omitempty"` Schema *Schema `json:"-" yaml:"-"` Links map[string]string `json:"links" yaml:"links"` Actions map[string]string `json:"actions" yaml:"actions"` Values map[string]interface{} `json:",inline"` ActionLinks bool `json:"-"` }
func (*RawResource) MarshalJSON ¶
func (r *RawResource) MarshalJSON() ([]byte, error)
type ReferenceValidator ¶
type ReferenceValidator interface { Validate(resourceType, resourceID string) bool Lookup(resourceType, resourceID string) *RawResource }
type RequestHandler ¶
type RequestHandler func(request *APIContext) error
type ResourceCollection ¶
type ResourceCollection struct { Collection Data []Resource `json:"data,omitempty"` }
type ResponseWriter ¶
type ResponseWriter interface {
Write(apiContext *APIContext, code int, obj interface{})
}
type Schema ¶
type Schema struct { ID string `json:"id,omitempty"` CodeName string `json:"-"` CodeNamePlural string `json:"-"` PkgName string `json:"-"` Type string `json:"type,omitempty"` BaseType string `json:"baseType,omitempty"` SubContext string `json:"-,omitempty"` Links map[string]string `json:"links"` Version APIVersion `json:"version"` PluralName string `json:"pluralName,omitempty"` ResourceMethods []string `json:"resourceMethods,omitempty"` ResourceFields map[string]Field `json:"resourceFields"` ResourceActions map[string]Action `json:"resourceActions,omitempty"` CollectionMethods []string `json:"collectionMethods,omitempty"` CollectionFields map[string]Field `json:"collectionFields,omitempty"` CollectionActions map[string]Action `json:"collectionActions,omitempty"` CollectionFilters map[string]Filter `json:"collectionFilters,omitempty"` Scope TypeScope `json:"-"` InternalSchema *Schema `json:"-"` Mapper Mapper `json:"-"` ActionHandler ActionHandler `json:"-"` LinkHandler RequestHandler `json:"-"` ListHandler RequestHandler `json:"-"` CreateHandler RequestHandler `json:"-"` DeleteHandler RequestHandler `json:"-"` UpdateHandler RequestHandler `json:"-"` Formatter Formatter `json:"-"` ErrorHandler ErrorHandler `json:"-"` Validator Validator `json:"-"` Store Store `json:"-"` }
type SchemaCollection ¶
type SchemaCollection struct {
Data []Schema
}
type SchemaInitFunc ¶
type Schemas ¶
type Schemas struct { DefaultMappers MappersFactory DefaultPostMappers MappersFactory // contains filtered or unexported fields }
func NewSchemas ¶
func NewSchemas() *Schemas
func (*Schemas) AddMapper ¶
func (s *Schemas) AddMapper(version *APIVersion, schemaID string, mapper Mapper) *Schemas
func (*Schemas) AddMapperForType ¶
func (s *Schemas) AddMapperForType(version *APIVersion, obj interface{}, mapper ...Mapper) *Schemas
func (*Schemas) AddSchemas ¶
func (*Schemas) Import ¶
func (s *Schemas) Import(version *APIVersion, obj interface{}, externalOverrides ...interface{}) (*Schema, error)
func (*Schemas) Init ¶
func (s *Schemas) Init(initFunc SchemaInitFunc) *Schemas
func (*Schemas) MustCustomizeType ¶
func (s *Schemas) MustCustomizeType(version *APIVersion, obj interface{}, f func(*Schema)) *Schemas
func (*Schemas) MustImport ¶
func (s *Schemas) MustImport(version *APIVersion, obj interface{}, externalOverrides ...interface{}) *Schemas
func (*Schemas) MustImportAndCustomize ¶
func (s *Schemas) MustImportAndCustomize(version *APIVersion, obj interface{}, f func(*Schema), externalOverrides ...interface{}) *Schemas
func (*Schemas) SchemasForVersion ¶
func (s *Schemas) SchemasForVersion(version APIVersion) map[string]*Schema
func (*Schemas) SubContext ¶
func (*Schemas) SubContextSchemas ¶
func (*Schemas) Versions ¶
func (s *Schemas) Versions() []APIVersion
type Store ¶
type Store interface { ByID(apiContext *APIContext, schema *Schema, id string) (map[string]interface{}, error) List(apiContext *APIContext, schema *Schema, opt QueryOptions) ([]map[string]interface{}, error) Create(apiContext *APIContext, schema *Schema, data map[string]interface{}) (map[string]interface{}, error) Update(apiContext *APIContext, schema *Schema, data map[string]interface{}, id string) (map[string]interface{}, error) Delete(apiContext *APIContext, schema *Schema, id string) error Watch(apiContext *APIContext, schema *Schema, opt QueryOptions) (chan map[string]interface{}, error) }
type SubContextAttributeProvider ¶
type SubContextAttributeProvider interface { Query(apiContext *APIContext, schema *Schema) []*QueryCondition Create(apiContext *APIContext, schema *Schema) map[string]interface{} }
type URLBuilder ¶
type URLBuilder interface { Current() string Collection(schema *Schema, versionOverride *APIVersion) string SubContextCollection(subContext *Schema, contextName string, schema *Schema) string SchemaLink(schema *Schema) string ResourceLink(resource *RawResource) string Link(linkName string, resource *RawResource) string RelativeToRoot(path string) string Version(version APIVersion) string Marker(marker string) string ReverseSort(order SortOrder) string Sort(field string) string SetSubContext(subContext string) }
type Validator ¶
type Validator func(request *APIContext, data map[string]interface{}) error
Source Files ¶
Click to show internal directories.
Click to hide internal directories.