types

package
v0.0.0-...-eef2c6e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ASC  = SortOrder("asc")
	DESC = SortOrder("desc")
)

Functions

func NewErrors

func NewErrors(errors []error) error

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 AccessControl interface {
	CanCreate(schema *Schema) bool
	CanList(schema *Schema) bool
}

type Action

type Action struct {
	Input  string `json:"input,omitempty"`
	Output string `json:"output,omitempty"`
}

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 ListOpts

type ListOpts struct {
	Filters map[string]interface{}
}

type Mapper

type Mapper interface {
	FromInternal(data map[string]interface{})
	ToInternal(data map[string]interface{})
	ModifySchema(schema *Schema, schemas *Schemas) error
}

type Mappers

type Mappers []Mapper

func (Mappers) FromInternal

func (m Mappers) FromInternal(data map[string]interface{})

func (Mappers) ModifySchema

func (m Mappers) ModifySchema(schema *Schema, schemas *Schemas) error

func (Mappers) ToInternal

func (m Mappers) ToInternal(data map[string]interface{})

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 Resource

type Resource struct {
	ID      string            `json:"id,omitempty"`
	Type    string            `json:"type,omitempty"`
	Links   map[string]string `json:"links"`
	Actions map[string]string `json:"actions"`
}

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:"-"`
}

func (*Schema) CanDelete

func (s *Schema) CanDelete() bool

func (*Schema) CanList

func (s *Schema) CanList() bool

func (*Schema) CanUpdate

func (s *Schema) CanUpdate() bool

func (*Schema) MustCustomizeField

func (s *Schema) MustCustomizeField(name string, f func(f Field) Field) *Schema

type SchemaCollection

type SchemaCollection struct {
	Data []Schema
}

type SchemaInitFunc

type SchemaInitFunc func(*Schemas) *Schemas

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) AddSchema

func (s *Schemas) AddSchema(schema *Schema) *Schemas

func (*Schemas) AddSchemas

func (s *Schemas) AddSchemas(schema *Schemas) *Schemas

func (*Schemas) Err

func (s *Schemas) Err() error

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) Schema

func (s *Schemas) Schema(version *APIVersion, name string) *Schema

func (*Schemas) Schemas

func (s *Schemas) Schemas() []*Schema

func (*Schemas) SchemasForVersion

func (s *Schemas) SchemasForVersion(version APIVersion) map[string]*Schema

func (*Schemas) SubContext

func (s *Schemas) SubContext(subContext string) *Schema

func (*Schemas) SubContextSchemas

func (s *Schemas) SubContextSchemas() map[string]*Schema

func (*Schemas) Versions

func (s *Schemas) Versions() []APIVersion

type Sort

type Sort struct {
	Name    string            `json:"name,omitempty"`
	Order   SortOrder         `json:"order,omitempty"`
	Reverse string            `json:"reverse,omitempty"`
	Links   map[string]string `json:"links,omitempty"`
}

type SortOrder

type SortOrder string

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 TypeScope

type TypeScope string
var NamespaceScope TypeScope = "namespace"

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

type ValuesMap

type ValuesMap struct {
	Foo map[string]interface{}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL