Documentation ¶
Index ¶
- Variables
- func APIChan(c <-chan APIEvent, f func(APIObject) APIObject) chan APIEvent
- func JSONEncoder(writer io.Writer, v interface{}) error
- func JSONLinesEncoder(writer io.Writer, v interface{}) error
- func Name(d map[string]interface{}) string
- func Namespace(d map[string]interface{}) string
- func YAMLEncoder(writer io.Writer, v interface{}) error
- type APIEvent
- type APIObject
- type APIObjectList
- type APIRequest
- func (r *APIRequest) Clone() *APIRequest
- func (r *APIRequest) Context() context.Context
- 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) WriteError(err error)
- func (r *APIRequest) WriteResponse(code int, obj APIObject)
- func (r *APIRequest) WriteResponseList(code int, list APIObjectList)
- type APISchema
- type APISchemas
- func (a *APISchemas) AddSchema(schema APISchema) error
- func (a *APISchemas) AddSchemas(schema *APISchemas) error
- func (a *APISchemas) Import(obj interface{}) (*APISchema, error)
- func (a *APISchemas) LookupSchema(name string) *APISchema
- func (a *APISchemas) MustAddSchema(obj APISchema) *APISchemas
- func (a *APISchemas) MustAddSchemas(schemas *APISchemas) *APISchemas
- func (a *APISchemas) MustImportAndCustomize(obj interface{}, f func(*APISchema))
- func (a *APISchemas) ShallowCopy() *APISchemas
- type AccessControl
- type Collection
- type CollectionFormatter
- type Condition
- type ErrorHandler
- type Formatter
- type GenericCollection
- type ModifierType
- type NamedResource
- type NamedResourceCollection
- type Pagination
- type RawResource
- type RequestHandler
- type RequestListHandler
- type RequestModifier
- type Resource
- type ResponseWriter
- type Store
- type URLBuilder
- type WatchRequest
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ChangeAPIEvent = "resource.change" RemoveAPIEvent = "resource.remove" CreateAPIEvent = "resource.create" )
Functions ¶
func JSONEncoder ¶
func JSONLinesEncoder ¶
func YAMLEncoder ¶
Types ¶
type APIEvent ¶
type APIEvent struct { Name string `json:"name,omitempty"` Namespace string `json:"namespace,omitempty"` ResourceType string `json:"resourceType,omitempty"` ID string `json:"id,omitempty"` Selector string `json:"selector,omitempty"` Revision string `json:"revision,omitempty"` Object APIObject `json:"-"` Error error `json:"-"` // Data is the output format of the object Data interface{} `json:"data,omitempty"` }
type APIObject ¶
func DefaultByID ¶
type APIObjectList ¶
type APIRequest ¶
type APIRequest struct { Action string Name string Type string Link string Method string Namespace string Schema *APISchema Schemas *APISchemas Query url.Values ResponseFormat string ResponseWriter ResponseWriter ErrorHandler ErrorHandler URLPrefix string URLBuilder URLBuilder AccessControl AccessControl Request *http.Request Response http.ResponseWriter }
func GetAPIContext ¶
func GetAPIContext(ctx context.Context) *APIRequest
func StoreAPIContext ¶
func StoreAPIContext(apiOp *APIRequest) *APIRequest
func (*APIRequest) Clone ¶
func (r *APIRequest) Clone() *APIRequest
func (*APIRequest) Context ¶
func (r *APIRequest) Context() context.Context
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) WriteError ¶
func (r *APIRequest) WriteError(err error)
func (*APIRequest) WriteResponse ¶
func (r *APIRequest) WriteResponse(code int, obj APIObject)
func (*APIRequest) WriteResponseList ¶
func (r *APIRequest) WriteResponseList(code int, list APIObjectList)
type APISchema ¶
type APISchema struct { *schemas.Schema ActionHandlers map[string]http.Handler `json:"-"` LinkHandlers map[string]http.Handler `json:"-"` ListHandler RequestListHandler `json:"-"` ByIDHandler RequestHandler `json:"-"` CreateHandler RequestHandler `json:"-"` DeleteHandler RequestHandler `json:"-"` UpdateHandler RequestHandler `json:"-"` Formatter Formatter `json:"-"` RequestModifier RequestModifier `json:"-"` CollectionFormatter CollectionFormatter `json:"-"` ErrorHandler ErrorHandler `json:"-"` Store Store `json:"-"` }
type APISchemas ¶
type APISchemas struct { InternalSchemas *schemas.Schemas Schemas map[string]*APISchema Attributes map[string]interface{} // contains filtered or unexported fields }
func EmptyAPISchemas ¶
func EmptyAPISchemas() *APISchemas
func (*APISchemas) AddSchema ¶
func (a *APISchemas) AddSchema(schema APISchema) error
func (*APISchemas) AddSchemas ¶
func (a *APISchemas) AddSchemas(schema *APISchemas) error
func (*APISchemas) Import ¶
func (a *APISchemas) Import(obj interface{}) (*APISchema, error)
func (*APISchemas) LookupSchema ¶
func (a *APISchemas) LookupSchema(name string) *APISchema
func (*APISchemas) MustAddSchema ¶
func (a *APISchemas) MustAddSchema(obj APISchema) *APISchemas
func (*APISchemas) MustAddSchemas ¶
func (a *APISchemas) MustAddSchemas(schemas *APISchemas) *APISchemas
func (*APISchemas) MustImportAndCustomize ¶
func (a *APISchemas) MustImportAndCustomize(obj interface{}, f func(*APISchema))
func (*APISchemas) ShallowCopy ¶
func (a *APISchemas) ShallowCopy() *APISchemas
type AccessControl ¶
type AccessControl interface { CanAction(apiOp *APIRequest, schema *APISchema, name string) error CanCreate(apiOp *APIRequest, schema *APISchema) error CanList(apiOp *APIRequest, schema *APISchema) error CanGet(apiOp *APIRequest, schema *APISchema) error CanUpdate(apiOp *APIRequest, obj APIObject, schema *APISchema) error CanDelete(apiOp *APIRequest, obj APIObject, schema *APISchema) error CanWatch(apiOp *APIRequest, schema *APISchema) error CanDo(apiOp *APIRequest, resource, verb, namespace, name string) 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"` ResourceType string `json:"resourceType"` Pagination *Pagination `json:"pagination,omitempty"` Revision string `json:"revision,omitempty"` Continue string `json:"continue,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 ErrorHandler ¶
type ErrorHandler func(request *APIRequest, err error)
type Formatter ¶
type Formatter func(request *APIRequest, resource *RawResource)
func FormatterChain ¶
type GenericCollection ¶
type GenericCollection struct { Collection Data []*RawResource `json:"data"` }
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 NamedResource ¶
type NamedResourceCollection ¶
type NamedResourceCollection struct { Collection Data []NamedResource `json:"data,omitempty"` }
type Pagination ¶
type RawResource ¶
type RawResource struct { ID string `json:"id,omitempty" yaml:"id,omitempty"` Type string `json:"type,omitempty" yaml:"type,omitempty"` Schema *APISchema `json:"-" yaml:"-"` Links map[string]string `json:"links" yaml:"links,omitempty"` Actions map[string]string `json:"actions,omitempty" yaml:"actions,omitempty"` ActionLinks bool `json:"-" yaml:"-"` APIObject APIObject `json:"-" yaml:"-"` }
func (*RawResource) AddAction ¶
func (r *RawResource) AddAction(apiOp *APIRequest, name string)
func (*RawResource) MarshalJSON ¶
func (r *RawResource) MarshalJSON() ([]byte, error)
type RequestHandler ¶
type RequestHandler func(request *APIRequest) (APIObject, error)
type RequestListHandler ¶
type RequestListHandler func(request *APIRequest) (APIObjectList, error)
type RequestModifier ¶
type RequestModifier func(request *APIRequest, schema *APISchema) *APISchema
type ResponseWriter ¶
type ResponseWriter interface { Write(apiOp *APIRequest, code int, obj APIObject) WriteList(apiOp *APIRequest, code int, obj APIObjectList) }
type Store ¶
type Store interface { ByID(apiOp *APIRequest, schema *APISchema, id string) (APIObject, error) List(apiOp *APIRequest, schema *APISchema) (APIObjectList, error) Create(apiOp *APIRequest, schema *APISchema, data APIObject) (APIObject, error) Update(apiOp *APIRequest, schema *APISchema, data APIObject, id string) (APIObject, error) Delete(apiOp *APIRequest, schema *APISchema, id string) (APIObject, error) Watch(apiOp *APIRequest, schema *APISchema, w WatchRequest) (chan APIEvent, error) }
type URLBuilder ¶
type URLBuilder interface { Current() string Collection(schema *APISchema) string CollectionAction(schema *APISchema, action string) string ResourceLink(schema *APISchema, id string) string Link(schema *APISchema, id string, linkName string) string Action(schema *APISchema, id string, action string) string Marker(marker string) string RelativeToRoot(path string) string }
type WatchRequest ¶
Click to show internal directories.
Click to hide internal directories.