Documentation
¶
Index ¶
- Variables
- func NewErrors(errors []error) error
- func ValidMod(mod string) bool
- type APIContext
- 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 Pagination
- type QueryCondition
- func EQ(value interface{}) *QueryCondition
- func IN(values ...interface{}) *QueryCondition
- func NE(value interface{}) *QueryCondition
- func NOTIN(values ...interface{}) *QueryCondition
- func NOTNULL(value interface{}) *QueryCondition
- func NULL(value interface{}) *QueryCondition
- func NewCondition(mod QueryConditionType, values ...interface{}) *QueryCondition
- func NewConditionFromString(field, mod string, values ...interface{}) *QueryCondition
- type QueryConditionType
- type QueryOptions
- type RawResource
- type ReferenceValidator
- type RequestHandler
- type Resource
- type ResourceCollection
- type ResponseWriter
- type Schema
- type SchemaCollection
- 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) MustImport(version *APIVersion, obj interface{}, externalOverrides ...interface{}) *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) Versions() []APIVersion
- type Sort
- type SortOrder
- type Store
- type TypeMapper
- type URLBuilder
- type Validator
- type ValuesMap
Constants ¶
This section is empty.
Variables ¶
View Source
var ( COND_EQ = QueryConditionType{"eq", 1} COND_NE = QueryConditionType{"ne", 1} COND_NULL = QueryConditionType{"null", 0} COND_NOTNULL = QueryConditionType{"notnull", 0} COND_IN = QueryConditionType{"in", -1} COND_NOTIN = QueryConditionType{"notin", -1} COND_OR = QueryConditionType{"or", 1} COND_AND = QueryConditionType{"and", 1} )
View Source
var ( ASC = SortOrder("asc") DESC = SortOrder("desc") )
Functions ¶
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 QueryOptions *QueryOptions Body map[string]interface{} URLBuilder URLBuilder AccessControl AccessControl SubContext map[string]interface{} Request *http.Request Response http.ResponseWriter }
func (*APIContext) WriteResponse ¶
func (r *APIContext) WriteResponse(code int, obj interface{})
type APIVersion ¶
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 string `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 Formatter ¶
type Formatter func(request *APIContext, resource *RawResource)
type GenericCollection ¶
type GenericCollection struct { Collection Data []interface{} `json:"data"` }
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"` Limit *int64 `json:"limit,omitempty"` Total *int64 `json:"total,omitempty"` Partial bool `json:"partial,omitempty"` }
type QueryCondition ¶
type QueryCondition struct { Field string Values []interface{} // contains filtered or unexported fields }
func EQ ¶
func EQ(value interface{}) *QueryCondition
func IN ¶
func IN(values ...interface{}) *QueryCondition
func NE ¶
func NE(value interface{}) *QueryCondition
func NOTIN ¶
func NOTIN(values ...interface{}) *QueryCondition
func NOTNULL ¶
func NOTNULL(value interface{}) *QueryCondition
func NULL ¶
func NULL(value interface{}) *QueryCondition
func NewCondition ¶
func NewCondition(mod QueryConditionType, values ...interface{}) *QueryCondition
func NewConditionFromString ¶
func NewConditionFromString(field, mod string, values ...interface{}) *QueryCondition
func (*QueryCondition) AND ¶
func (c *QueryCondition) AND(right *QueryCondition) *QueryCondition
func (*QueryCondition) OR ¶
func (c *QueryCondition) OR(right *QueryCondition) *QueryCondition
func (*QueryCondition) ToCondition ¶
func (q *QueryCondition) ToCondition() Condition
type QueryConditionType ¶
type QueryOptions ¶
type QueryOptions struct { Sort Sort Pagination *Pagination Conditions []*QueryCondition }
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"` 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,omitempty"` 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"` 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 Schemas ¶
type Schemas struct {
// 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) MustImport ¶
func (s *Schemas) MustImport(version *APIVersion, obj interface{}, externalOverrides ...interface{}) *Schemas
func (*Schemas) SchemasForVersion ¶
func (s *Schemas) SchemasForVersion(version APIVersion) map[string]*Schema
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 }
type TypeMapper ¶
type TypeMapper struct { Mappers []Mapper // contains filtered or unexported fields }
func (*TypeMapper) FromInternal ¶
func (t *TypeMapper) FromInternal(data map[string]interface{})
func (*TypeMapper) ModifySchema ¶
func (t *TypeMapper) ModifySchema(schema *Schema, schemas *Schemas) error
func (*TypeMapper) ToInternal ¶
func (t *TypeMapper) ToInternal(data map[string]interface{})
type URLBuilder ¶
type URLBuilder interface { Current() string Collection(schema *Schema) string ResourceLink(resource *RawResource) string RelativeToRoot(path string) string //Link(resource Resource, name string) string //ReferenceLink(resource Resource) string //ReferenceByIdLink(resourceType string, id string) string Version(version string) string ReverseSort(order SortOrder) 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.