Documentation
¶
Index ¶
- type AbstractResource
- func (ar *AbstractResource) Create(request *http.Request) (string, Attributes, error)
- func (ar *AbstractResource) GetAll(request *http.Request) map[string]Attributes
- func (ar *AbstractResource) GetByID(request *http.Request, id string) Attributes
- func (ar *AbstractResource) GetCustomRoutes() map[string]CustomRoute
- func (ar *AbstractResource) GetRouter() chi.Router
- func (ar *AbstractResource) GetServer() interface{}
- func (ar *AbstractResource) GetSingle(request *http.Request) (string, Attributes)
- func (ar *AbstractResource) Initialize(parentLogger nuclio.Logger, server interface{}) (chi.Router, error)
- func (ar *AbstractResource) OnAfterInitialize()
- func (ar *AbstractResource) Register(registry *registry.Registry)
- func (ar *AbstractResource) Remove(request *http.Request, id string) error
- func (ar *AbstractResource) Update(request *http.Request, id string) (Attributes, error)
- type Attributes
- type CustomRoute
- type CustomRouteFunc
- type Encoder
- type EncoderFactory
- type JSONAPIEncoderFactory
- type JSONEncoderFactory
- type Resource
- type ResourceMethod
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AbstractResource ¶
type AbstractResource struct {
Logger nuclio.Logger
Resource Resource
// contains filtered or unexported fields
}
func NewAbstractResource ¶
func NewAbstractResource(name string, resourceMethods []ResourceMethod) *AbstractResource
func (*AbstractResource) Create ¶
func (ar *AbstractResource) Create(request *http.Request) (string, Attributes, error)
create a resource
func (*AbstractResource) GetAll ¶
func (ar *AbstractResource) GetAll(request *http.Request) map[string]Attributes
return all instances for resources with multiple instances
func (*AbstractResource) GetByID ¶
func (ar *AbstractResource) GetByID(request *http.Request, id string) Attributes
return specific instance by ID
func (*AbstractResource) GetCustomRoutes ¶
func (ar *AbstractResource) GetCustomRoutes() map[string]CustomRoute
returns a list of custom routes for the resource
func (*AbstractResource) GetRouter ¶
func (ar *AbstractResource) GetRouter() chi.Router
for raw routes, those that don't return an attribute
func (*AbstractResource) GetServer ¶
func (ar *AbstractResource) GetServer() interface{}
func (*AbstractResource) GetSingle ¶
func (ar *AbstractResource) GetSingle(request *http.Request) (string, Attributes)
return all instances for resources with single instances
func (*AbstractResource) Initialize ¶
func (*AbstractResource) OnAfterInitialize ¶
func (ar *AbstractResource) OnAfterInitialize()
called after initialization
func (*AbstractResource) Register ¶
func (ar *AbstractResource) Register(registry *registry.Registry)
func (*AbstractResource) Remove ¶
func (ar *AbstractResource) Remove(request *http.Request, id string) error
func (*AbstractResource) Update ¶
func (ar *AbstractResource) Update(request *http.Request, id string) (Attributes, error)
type Attributes ¶
type Attributes map[string]interface{}
type CustomRoute ¶
type CustomRoute struct {
Method string
RouteFunc CustomRouteFunc
}
type CustomRouteFunc ¶
A custom route returns: resource type: string resources: a map of resource ID, resource attributes single: whether or not the resources should be treated as a single resource (if false, will be returned as list) status code: status code to return error: an error, if something went wrong
type Encoder ¶
type Encoder interface {
// encode a single resource
EncodeResource(string, Attributes)
// encode multiple resources
EncodeResources(map[string]Attributes)
}
type EncoderFactory ¶
type EncoderFactory interface {
// create an encoder
NewEncoder(http.ResponseWriter, string) Encoder
}
type JSONAPIEncoderFactory ¶
type JSONAPIEncoderFactory struct{}
func (*JSONAPIEncoderFactory) NewEncoder ¶
func (jaef *JSONAPIEncoderFactory) NewEncoder(responseWriter http.ResponseWriter, resourceType string) Encoder
type JSONEncoderFactory ¶
type JSONEncoderFactory struct{}
func (*JSONEncoderFactory) NewEncoder ¶
func (jef *JSONEncoderFactory) NewEncoder(responseWriter http.ResponseWriter, resourceType string) Encoder
type Resource ¶
type Resource interface {
// Called after initialization
OnAfterInitialize()
// returns a list of custom routes for the resource
GetCustomRoutes() map[string]CustomRoute
// return all instances for resources with multiple instances
GetAll(request *http.Request) map[string]Attributes
// return all instances for resources with single instances
GetSingle(request *http.Request) (string, Attributes)
// return specific instance by ID
GetByID(request *http.Request, id string) Attributes
// returns resource ID, attributes
Create(request *http.Request) (string, Attributes, error)
// returns attributes (optionally)
Update(request *http.Request, id string) (Attributes, error)
// delete an entity
Remove(request *http.Request, id string) error
}
type ResourceMethod ¶
type ResourceMethod int
const ( ResourceMethodGetList ResourceMethod = iota ResourceMethodGetDetail ResourceMethodCreate ResourceMethodUpdate ResourceMethodDelete )
Click to show internal directories.
Click to hide internal directories.