Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateName(typeName string) string
- func JSONEncoder(writer io.Writer, v interface{}) error
- func NewErrors(inErrors ...error) error
- func ValidMod(mod ModifierType) bool
- func YAMLEncoder(writer io.Writer, v interface{}) error
- type APIContext
- func (r *APIContext) Filter(opts *QueryOptions, schema *Schema, obj interface{}) interface{}
- func (r *APIContext) FilterList(opts *QueryOptions, schema *Schema, obj []map[string]interface{}) []map[string]interface{}
- func (r *APIContext) FilterObject(opts *QueryOptions, schema *Schema, obj map[string]interface{}) map[string]interface{}
- func (r *APIContext) Option(key string) string
- func (r *APIContext) WriteResponse(code int, obj interface{})
- type APIVersion
- type AccessControl
- type Action
- type ActionHandler
- type BackReference
- type Collection
- type CollectionFormatter
- type Condition
- type ErrorHandler
- type Errors
- type Field
- type Filter
- type Formatter
- type GenericCollection
- type InputFormatter
- type ListOpts
- type Mapper
- type Mappers
- type MappersFactory
- type ModifierType
- type MultiErrors
- type NamedResource
- type NamedResourceCollection
- 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
- func (s *Schema) CanCreate(context *APIContext) error
- func (s *Schema) CanDelete(context *APIContext) error
- func (s *Schema) CanGet(context *APIContext) error
- func (s *Schema) CanList(context *APIContext) error
- func (s *Schema) CanUpdate(context *APIContext) error
- func (s *Schema) MustCustomizeField(name string, f func(f Field) Field) *Schema
- type SchemaCollection
- type SchemaHook
- 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) ForceAddSchema(schema Schema) *Schemas
- func (s *Schemas) Import(version *APIVersion, obj interface{}, externalOverrides ...interface{}) (*Schema, error)
- func (s *Schemas) Init(initFunc SchemasInitFunc) *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) References(schema *Schema) []BackReference
- func (s *Schemas) RemoveSchema(schema 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) SubContextVersionForSchema(schema *Schema) *APIVersion
- func (s *Schemas) TypeName(name string, obj interface{}) *Schemas
- func (s *Schemas) Versions() []APIVersion
- type SchemasInitFunc
- type Sort
- type SortOrder
- type StorageContext
- type Store
- type SubContextAttributeProvider
- type TypeScope
- type URLBuilder
- type Validator
- type ValuesMap
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") )
Functions ¶
func GenerateName ¶
func JSONEncoder ¶
func ValidMod ¶
func ValidMod(mod ModifierType) bool
func YAMLEncoder ¶
Types ¶
type APIContext ¶
type APIContext struct { Action string ID string Type string Link string Method string Schema *Schema Schemas *Schemas Version *APIVersion SchemasVersion *APIVersion Query url.Values ResponseFormat string ReferenceValidator ReferenceValidator ResponseWriter ResponseWriter QueryFilter QueryFilter SubContextAttributeProvider SubContextAttributeProvider URLBuilder URLBuilder AccessControl AccessControl SubContext map[string]string Pagination *Pagination Request *http.Request Response http.ResponseWriter }
func GetAPIContext ¶
func GetAPIContext(ctx context.Context) *APIContext
func NewAPIContext ¶
func NewAPIContext(req *http.Request, resp http.ResponseWriter, schemas *Schemas) *APIContext
func (*APIContext) Filter ¶
func (r *APIContext) Filter(opts *QueryOptions, schema *Schema, obj interface{}) interface{}
func (*APIContext) FilterList ¶
func (r *APIContext) FilterList(opts *QueryOptions, schema *Schema, obj []map[string]interface{}) []map[string]interface{}
func (*APIContext) FilterObject ¶
func (r *APIContext) FilterObject(opts *QueryOptions, schema *Schema, obj map[string]interface{}) map[string]interface{}
func (*APIContext) Option ¶
func (r *APIContext) Option(key string) string
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"` SubContext bool `json:"subContext,omitempty"` SubContextSchema string `json:"filterField,omitempty"` }
func (*APIVersion) Equals ¶
func (v *APIVersion) Equals(other *APIVersion) bool
type AccessControl ¶
type AccessControl interface { CanCreate(apiContext *APIContext, schema *Schema) error CanList(apiContext *APIContext, schema *Schema) error CanGet(apiContext *APIContext, schema *Schema) error CanUpdate(apiContext *APIContext, obj map[string]interface{}, schema *Schema) error CanDelete(apiContext *APIContext, obj map[string]interface{}, schema *Schema) error // CanDo function should not yet be used if a corresponding specific method exists. It has been added to // satisfy a specific usecase for the short term until full-blown dynamic RBAC can be implemented. CanDo(apiGroup, resource, verb string, apiContext *APIContext, obj map[string]interface{}, schema *Schema) error Filter(apiContext *APIContext, schema *Schema, obj map[string]interface{}, context map[string]string) map[string]interface{} FilterList(apiContext *APIContext, schema *Schema, obj []map[string]interface{}, context map[string]string) []map[string]interface{} }
type ActionHandler ¶
type ActionHandler func(actionName string, action *Action, request *APIContext) error
type BackReference ¶
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"` }
func (*Collection) AddAction ¶
func (c *Collection) AddAction(apiContext *APIContext, name string)
type CollectionFormatter ¶
type CollectionFormatter func(request *APIContext, collection *GenericCollection)
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"` 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"` CodeName string `json:"-"` DynamicField bool `json:"dynamicField,omitempty"` }
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 InputFormatter ¶
type InputFormatter func(request *APIContext, schema *Schema, data map[string]interface{}, create bool) error
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 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 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 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 []map[string]interface{}) []map[string]interface{}
type QueryOptions ¶
type QueryOptions struct { Sort Sort Pagination *Pagination Conditions []*QueryCondition Options map[string]string // Set namespaces to an empty array will result in an empty response Namespaces []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(apiContext *APIContext, 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 *APIContext, next RequestHandler) 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"` Embed bool `json:"embed,omitempty"` EmbedType string `json:"embedType,omitempty"` CodeName string `json:"-"` CodeNamePlural string `json:"-"` PkgName string `json:"-"` Type string `json:"type,omitempty"` BaseType string `json:"baseType,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"` DynamicSchemaVersion string `json:"dynamicSchemaVersion,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:"-"` 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 *APIContext) error
func (*Schema) CanDelete ¶
func (s *Schema) CanDelete(context *APIContext) error
func (*Schema) CanGet ¶
func (s *Schema) CanGet(context *APIContext) error
func (*Schema) CanList ¶
func (s *Schema) CanList(context *APIContext) error
func (*Schema) CanUpdate ¶
func (s *Schema) CanUpdate(context *APIContext) error
type SchemaCollection ¶
type SchemaCollection struct {
Data []Schema
}
type SchemaHook ¶
type SchemaHook func(*Schema)
type Schemas ¶
type Schemas struct { sync.Mutex DefaultMappers MappersFactory DefaultPostMappers MappersFactory AddHook SchemaHook // 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) ForceAddSchema ¶
func (*Schemas) Import ¶
func (s *Schemas) Import(version *APIVersion, obj interface{}, externalOverrides ...interface{}) (*Schema, error)
func (*Schemas) Init ¶
func (s *Schemas) Init(initFunc SchemasInitFunc) *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) References ¶
func (s *Schemas) References(schema *Schema) []BackReference
func (*Schemas) RemoveSchema ¶
func (*Schemas) SchemasForVersion ¶
func (s *Schemas) SchemasForVersion(version APIVersion) map[string]*Schema
func (*Schemas) SubContextVersionForSchema ¶
func (s *Schemas) SubContextVersionForSchema(schema *Schema) *APIVersion
func (*Schemas) Versions ¶
func (s *Schemas) Versions() []APIVersion
type SchemasInitFunc ¶
type Store ¶
type Store interface { Context() StorageContext 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) (map[string]interface{}, 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 CollectionAction(schema *Schema, versionOverride *APIVersion, action string) 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) FilterLink(schema *Schema, fieldName string, value string) string Action(action string, resource *RawResource) string ResourceLinkByID(schema *Schema, id string) string ActionLinkByID(schema *Schema, id string, action string) string }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.