Documentation ¶
Overview ¶
Package goresource provides a micro REST framework.
Index ¶
- type DefaultManager
- func (manager DefaultManager) CreateEntity(e Entity, _ url.Values) (interface{}, error)
- func (manager DefaultManager) DeleteEntity(id string, _ url.Values) error
- func (manager DefaultManager) GetEntity(id string, _ url.Values) (interface{}, error)
- func (manager DefaultManager) GetName() string
- func (manager DefaultManager) ListEntities(query url.Values) (interface{}, error)
- func (manager DefaultManager) UpdateEntity(id string, e Entity, _ url.Values) (interface{}, error)
- type Entity
- type Resource
- func (r Resource) Delete(rw http.ResponseWriter, req *http.Request)
- func (r Resource) Get(rw http.ResponseWriter, req *http.Request)
- func (r Resource) Head(rw http.ResponseWriter, req *http.Request)
- func (r Resource) Patch(rw http.ResponseWriter, req *http.Request)
- func (r Resource) PostOrPut(rw http.ResponseWriter, req *http.Request)
- func (r Resource) ServeHTTP(rw http.ResponseWriter, req *http.Request)
- func (r Resource) UnsupportedMethod(rw http.ResponseWriter, req *http.Request)
- type ResourceManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DefaultManager ¶
type DefaultManager struct { // Name is used a prefix for routes as well as the database collection name. Name string Store store.Store }
DefaultManager is a default implementation for ResourceManager. It implements defaults for all methods except New and ParseJSON.
func NewDefaultManager ¶
func NewDefaultManager(name string, store store.Store) DefaultManager
NewDefaultManager initializes and returns a DefaultManager.
func (DefaultManager) CreateEntity ¶
func (manager DefaultManager) CreateEntity(e Entity, _ url.Values) (interface{}, error)
CreateEntity persists the given entity.
func (DefaultManager) DeleteEntity ¶
func (manager DefaultManager) DeleteEntity(id string, _ url.Values) error
DeleteEntity removes a single entity with the given id.
func (DefaultManager) GetEntity ¶
func (manager DefaultManager) GetEntity(id string, _ url.Values) (interface{}, error)
GetEntity fetches a single resource entity with the given id.
func (DefaultManager) GetName ¶
func (manager DefaultManager) GetName() string
GetName returns the name for this DefaultManager.
func (DefaultManager) ListEntities ¶
func (manager DefaultManager) ListEntities(query url.Values) (interface{}, error)
ListEntities fetches all resource entities.
func (DefaultManager) UpdateEntity ¶
UpdateEntity persists changes to the given entity with the given id.
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource provides an abstraction to be able to store and retrieve entities via a RESTful api. It is responsible for request handling and writing responses. The acutal persistence and any entity specific operations are delegated to the corresponding ResourceManager. This decouples request handing and persistence from specific entity types.
func NewResource ¶
func NewResource(m ResourceManager, router *mux.Router) *Resource
NewResource instantiates a Resource and binds routes to the given mux router, to serve the api end points specific to this resource.
func (Resource) Delete ¶
func (r Resource) Delete(rw http.ResponseWriter, req *http.Request)
Delete is the delegate http handler for delete requests for this resource.
func (Resource) Get ¶
func (r Resource) Get(rw http.ResponseWriter, req *http.Request)
Get is the delegate http handler for get requests for this resource.
func (Resource) Head ¶
func (r Resource) Head(rw http.ResponseWriter, req *http.Request)
Head is the delegate http handler for head requests for this resource.
func (Resource) Patch ¶
func (r Resource) Patch(rw http.ResponseWriter, req *http.Request)
Patch is the delegate http handler for patch requests for this resource.
func (Resource) PostOrPut ¶
func (r Resource) PostOrPut(rw http.ResponseWriter, req *http.Request)
PostOrPut is the common code between put and post requests. TODO: This is partially incorrect according to the spec. PUT without an id in the uri is invalid and should return a BadRequest error. Fix this to comply to with the spec.
func (Resource) ServeHTTP ¶
func (r Resource) ServeHTTP(rw http.ResponseWriter, req *http.Request)
ServeHTTP is the main http handler that handles all api request for this resource. It delegates based on HTTP Method to other methods of this resource.
func (Resource) UnsupportedMethod ¶
func (r Resource) UnsupportedMethod(rw http.ResponseWriter, req *http.Request)
UnsupportedMethod is the delegate http handler for unknown requests types. This is the catch-all when request method is not known.
type ResourceManager ¶
type ResourceManager interface { GetName() string New() Entity GetEntity(id string, query url.Values) (interface{}, error) CreateEntity(entity Entity, query url.Values) (interface{}, error) ListEntities(query url.Values) (interface{}, error) UpdateEntity(id string, entity Entity, query url.Values) (interface{}, error) DeleteEntity(id string, query url.Values) error ParseJSON(io.ReadCloser) (Entity, error) }
ResourceManager is an interface implemented by managers for entities.
Directories ¶
Path | Synopsis |
---|---|
Package mocks is a generated GoMock package.
|
Package mocks is a generated GoMock package. |
package store implements a database store for goresource.
|
package store implements a database store for goresource. |
Package util provides utility functions for goresource.
|
Package util provides utility functions for goresource. |