Documentation ¶
Index ¶
- Constants
- Variables
- func APIChan(c <-chan APIEvent, f func(APIObject) APIObject) chan APIEvent
- func GenerateName(typeName string) string
- func JSONEncoder(writer io.Writer, v interface{}) error
- func Name(data map[string]interface{}) string
- func Namespace(data map[string]interface{}) string
- func NewErrors(inErrors ...error) error
- func ValidMod(mod ModifierType) bool
- func YAMLEncoder(writer io.Writer, v interface{}) error
- type APIEvent
- type APIObject
- func (a *APIObject) First() APIObject
- func (a *APIObject) IsList() bool
- func (a APIObject) IsNil() bool
- func (a *APIObject) List() data.List
- func (a *APIObject) ListCheck() (data.List, bool)
- func (a *APIObject) Map() data.Object
- func (a *APIObject) Name() string
- func (a *APIObject) Namespace() string
- func (a *APIObject) Raw() interface{}
- type APIRequest
- func (r *APIRequest) Context() context.Context
- func (r *APIRequest) Filter(opts *QueryOptions, schema *Schema, obj APIObject) APIObject
- func (r *APIRequest) FilterList(opts *QueryOptions, schema *Schema, obj APIObject) APIObject
- func (r *APIRequest) FilterObject(opts *QueryOptions, schema *Schema, obj APIObject) APIObject
- func (r *APIRequest) GetUser() string
- func (r *APIRequest) GetUserInfo() (user.Info, bool)
- func (r *APIRequest) Option(key string) string
- func (r *APIRequest) WithContext(ctx context.Context) *APIRequest
- func (r *APIRequest) WriteResponse(code int, obj interface{})
- type AccessControl
- type Action
- type ActionHandler
- type Collection
- type CollectionFormatter
- type Condition
- type EmptyMapper
- type ErrorHandler
- type Errors
- type Field
- type FieldMapperFactory
- type Filter
- type Formatter
- type GenericCollection
- type InputFormatter
- type ListOpts
- type Mapper
- type MapperFactory
- type Mappers
- type ModifierType
- type MultiErrors
- type NamedResource
- type NamedResourceCollection
- type Pagination
- type QueryCondition
- type QueryConditionType
- type QueryFilter
- type QueryOptions
- type RawResource
- type ReferenceValidator
- type RequestHandler
- type Resource
- type ResourceCollection
- type ResponseWriter
- type Schema
- func (s *Schema) CanCreate(context *APIRequest) error
- func (s *Schema) CanDelete(context *APIRequest) error
- func (s *Schema) CanGet(context *APIRequest) error
- func (s *Schema) CanList(context *APIRequest) error
- func (s *Schema) CanUpdate(context *APIRequest) error
- func (s *Schema) DeepCopy() *Schema
- func (s *Schema) MustCustomizeField(name string, f func(f Field) Field) *Schema
- type SchemaCollection
- type Schemas
- func (s *Schemas) AddFieldMapper(name string, factory FieldMapperFactory) *Schemas
- func (s *Schemas) AddMapper(schemaID string, mapper Mapper) *Schemas
- func (s *Schemas) AddMapperForType(obj interface{}, mapper ...Mapper) *Schemas
- func (s *Schemas) AddSchema(schema Schema) error
- func (s *Schemas) AddSchemas(schema *Schemas) (*Schemas, error)
- func (s *Schemas) Import(obj interface{}, externalOverrides ...interface{}) (*Schema, error)
- func (s *Schemas) Init(initFunc SchemasInitFunc) *Schemas
- func (s *Schemas) MustAddSchema(schema Schema) *Schemas
- func (s *Schemas) MustAddSchemas(schema *Schemas) *Schemas
- func (s *Schemas) MustCustomizeType(obj interface{}, f func(*Schema)) *Schemas
- func (s *Schemas) MustImport(obj interface{}, externalOverrides ...interface{}) *Schemas
- func (s *Schemas) MustImportAndCustomize(obj interface{}, f func(*Schema), externalOverrides ...interface{}) *Schemas
- func (s *Schemas) RemoveSchema(schema Schema) *Schemas
- func (s *Schemas) Schema(name string) *Schema
- func (s *Schemas) SchemaFor(t reflect.Type) *Schema
- func (s *Schemas) Schemas() []*Schema
- func (s *Schemas) SchemasByID() map[string]*Schema
- func (s *Schemas) TypeName(name string, obj interface{}) *Schemas
- type SchemasInitFunc
- type Sort
- type SortOrder
- type Store
- type URLBuilder
- type Validator
- type WatchRequest
Constants ¶
View Source
const (
ResourceFieldID = "id"
)
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") )
View Source
var ( ChangeAPIEvent = "resource.change" RemoveAPIEvent = "resource.remove" CreateAPIEvent = "resource.create" )
Functions ¶
func GenerateName ¶
func JSONEncoder ¶
func ValidMod ¶
func ValidMod(mod ModifierType) bool
func YAMLEncoder ¶
Types ¶
type APIObject ¶
type APIObject struct { ListRevision string `json:"-"` Object interface{} `json:",inline"` }
type APIRequest ¶
type APIRequest struct { Action string Name string Type string Link string Method string Namespaces []string Schema *Schema Schemas *Schemas Query url.Values ResponseFormat string ReferenceValidator ReferenceValidator ResponseWriter ResponseWriter QueryFilter QueryFilter URLPrefix string URLBuilder URLBuilder AccessControl AccessControl Pagination *Pagination Request *http.Request Response http.ResponseWriter }
func (*APIRequest) Context ¶
func (r *APIRequest) Context() context.Context
func (*APIRequest) Filter ¶
func (r *APIRequest) Filter(opts *QueryOptions, schema *Schema, obj APIObject) APIObject
func (*APIRequest) FilterList ¶
func (r *APIRequest) FilterList(opts *QueryOptions, schema *Schema, obj APIObject) APIObject
func (*APIRequest) FilterObject ¶
func (r *APIRequest) FilterObject(opts *QueryOptions, schema *Schema, obj APIObject) APIObject
func (*APIRequest) GetUser ¶
func (r *APIRequest) GetUser() string
func (*APIRequest) GetUserInfo ¶
func (r *APIRequest) GetUserInfo() (user.Info, bool)
func (*APIRequest) Option ¶
func (r *APIRequest) Option(key string) string
func (*APIRequest) WithContext ¶
func (r *APIRequest) WithContext(ctx context.Context) *APIRequest
func (*APIRequest) WriteResponse ¶
func (r *APIRequest) WriteResponse(code int, obj interface{})
type AccessControl ¶
type AccessControl interface { CanCreate(apiOp *APIRequest, schema *Schema) error CanList(apiOp *APIRequest, schema *Schema) error CanGet(apiOp *APIRequest, schema *Schema) error CanUpdate(apiOp *APIRequest, obj APIObject, schema *Schema) error CanDelete(apiOp *APIRequest, obj APIObject, schema *Schema) error CanWatch(apiOp *APIRequest, schema *Schema) error }
type ActionHandler ¶
type ActionHandler func(actionName string, action *Action, request *APIRequest) 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"` Revision string `json:"revision,omitempty"` }
func (*Collection) AddAction ¶
func (c *Collection) AddAction(apiOp *APIRequest, name string)
type CollectionFormatter ¶
type CollectionFormatter func(request *APIRequest, collection *GenericCollection)
type Condition ¶
type Condition struct { Modifier ModifierType `json:"modifier,omitempty"` Value interface{} `json:"value,omitempty"` }
type EmptyMapper ¶
type EmptyMapper struct { }
func (*EmptyMapper) FromInternal ¶
func (e *EmptyMapper) FromInternal(data data.Object)
func (*EmptyMapper) ModifySchema ¶
func (e *EmptyMapper) ModifySchema(schema *Schema, schemas *Schemas) error
func (*EmptyMapper) ToInternal ¶
func (e *EmptyMapper) ToInternal(data data.Object) error
type ErrorHandler ¶
type ErrorHandler func(request *APIRequest, 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"` WriteOnly bool `json:"writeOnly,omitempty"` Required bool `json:"required,omitempty"` Update bool `json:"update"` 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"` Dynamic bool `json:"dynamic,omitempty"` CodeName string `json:"-"` }
type FieldMapperFactory ¶
type Filter ¶
type Filter struct {
Modifiers []ModifierType `json:"modifiers,omitempty"`
}
type Formatter ¶
type Formatter func(request *APIRequest, resource *RawResource)
func FormatterChain ¶
type GenericCollection ¶
type GenericCollection struct { Collection Data []interface{} `json:"data"` }
type InputFormatter ¶
type InputFormatter func(request *APIRequest, schema *Schema, data APIObject, create bool) error
type MapperFactory ¶
type MapperFactory 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 MultiErrors ¶
type MultiErrors struct {
Errors []error
}
func (*MultiErrors) Error ¶
func (m *MultiErrors) Error() string
type NamedResource ¶
type NamedResourceCollection ¶
type NamedResourceCollection struct { Collection Data []NamedResource `json:"data,omitempty"` }
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 EQ ¶
func EQ(key, value string) *QueryCondition
func NewConditionFromString ¶
func NewConditionFromString(field string, mod ModifierType, values ...string) *QueryCondition
func (*QueryCondition) ToCondition ¶
func (q *QueryCondition) ToCondition() Condition
type QueryConditionType ¶
type QueryConditionType struct { Name ModifierType Args int }
type QueryFilter ¶
type QueryFilter func(opts *QueryOptions, schema *Schema, data APIObject) APIObject
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,omitempty" yaml:"links,omitempty"` Actions map[string]string `json:"actions,omitempty" yaml:"actions,omitempty"` Values map[string]interface{} `json:",inline" yaml:",inline"` ActionLinks bool `json:"-" yaml:"-"` DropReadOnly bool `json:"-" yaml:"-"` }
func (*RawResource) AddAction ¶
func (r *RawResource) AddAction(apiOp *APIRequest, name string)
func (*RawResource) MarshalJSON ¶
func (r *RawResource) MarshalJSON() ([]byte, error)
func (*RawResource) ToMap ¶
func (r *RawResource) ToMap() map[string]interface{}
type ReferenceValidator ¶
type ReferenceValidator interface { Validate(resourceType, resourceID string) bool Lookup(resourceType, resourceID string) *RawResource }
type RequestHandler ¶
type RequestHandler func(request *APIRequest) (APIObject, error)
type ResourceCollection ¶
type ResourceCollection struct { Collection Data []Resource `json:"data,omitempty"` }
type ResponseWriter ¶
type ResponseWriter interface {
Write(apiOp *APIRequest, code int, obj interface{})
}
type Schema ¶
type Schema struct { ID string `json:"id,omitempty"` Description string `json:"description,omitempty"` CodeName string `json:"-"` CodeNamePlural string `json:"-"` PkgName string `json:"-"` Type string `json:"type,omitempty"` Links map[string]string `json:"links"` 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"` Attributes map[string]interface{} `json:"attributes,omitempty"` Dynamic bool `json:"dynamic,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:"-"` InputFormatter InputFormatter `json:"-"` Formatter Formatter `json:"-"` CollectionFormatter CollectionFormatter `json:"-"` ErrorHandler ErrorHandler `json:"-"` Validator Validator `json:"-"` Store Store `json:"-"` }
func (*Schema) CanCreate ¶
func (s *Schema) CanCreate(context *APIRequest) error
func (*Schema) CanDelete ¶
func (s *Schema) CanDelete(context *APIRequest) error
func (*Schema) CanGet ¶
func (s *Schema) CanGet(context *APIRequest) error
func (*Schema) CanList ¶
func (s *Schema) CanList(context *APIRequest) error
func (*Schema) CanUpdate ¶
func (s *Schema) CanUpdate(context *APIRequest) error
type SchemaCollection ¶
type SchemaCollection struct {
Data []Schema
}
type Schemas ¶
type Schemas struct { sync.Mutex DefaultMapper MapperFactory DefaultPostMapper MapperFactory // contains filtered or unexported fields }
func EmptySchemas ¶
func EmptySchemas() *Schemas
func NewSchemas ¶
func (*Schemas) AddFieldMapper ¶
func (s *Schemas) AddFieldMapper(name string, factory FieldMapperFactory) *Schemas
func (*Schemas) AddMapperForType ¶
func (*Schemas) Init ¶
func (s *Schemas) Init(initFunc SchemasInitFunc) *Schemas
func (*Schemas) MustAddSchema ¶
func (*Schemas) MustAddSchemas ¶
func (*Schemas) MustCustomizeType ¶
func (*Schemas) MustImport ¶
func (*Schemas) MustImportAndCustomize ¶
func (*Schemas) RemoveSchema ¶
func (*Schemas) SchemasByID ¶
type SchemasInitFunc ¶
type Store ¶
type Store interface { ByID(apiOp *APIRequest, schema *Schema, id string) (APIObject, error) List(apiOp *APIRequest, schema *Schema, opt *QueryOptions) (APIObject, error) Create(apiOp *APIRequest, schema *Schema, data APIObject) (APIObject, error) Update(apiOp *APIRequest, schema *Schema, data APIObject, id string) (APIObject, error) Delete(apiOp *APIRequest, schema *Schema, id string) (APIObject, error) Watch(apiOp *APIRequest, schema *Schema, w WatchRequest) (chan APIEvent, error) }
type URLBuilder ¶
type URLBuilder interface { Current() string Collection(schema *Schema) string CollectionAction(schema *Schema, action string) string ResourceLink(schema *Schema, id string) string Link(schema *Schema, id string, linkName string) string FilterLink(schema *Schema, fieldName string, value string) string Action(schema *Schema, id string, action string) string RelativeToRoot(path string) string Marker(marker string) string ReverseSort(order SortOrder) string Sort(field string) string }
type WatchRequest ¶
type WatchRequest struct {
Revision string
}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.