Documentation ¶
Overview ¶
Package Presto gives you a strong foundation for creating REST interfaces using Go and the [Echo Router](http://echo.labstack.com)
Index ¶
- func IDScope(context echo.Context) (map[string]interface{}, *derp.Error)
- func RequestInfo(context echo.Context) map[string]string
- type Cache
- type Collection
- func (collection *Collection) Delete(roles ...RoleFunc) *Collection
- func (collection *Collection) Get(roles ...RoleFunc) *Collection
- func (collection *Collection) List(roles ...RoleFunc) *Collection
- func (collection *Collection) Method()
- func (collection *Collection) Patch(roles ...RoleFunc) *Collection
- func (collection *Collection) Post(roles ...RoleFunc) *Collection
- func (collection *Collection) Put(roles ...RoleFunc) *Collection
- func (collection *Collection) WithScopes(scopes ...ScopeFunc) *Collection
- type Object
- type RoleFunc
- type ScopeFunc
- type Service
- type ServiceFactory
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RequestInfo ¶
RequestInfo inspects a request and returns any information that might be useful for debugging problems. It is primarily used by internal methods whenever there's a problem with a request.
Types ¶
type Cache ¶
type Cache interface { // Get returns the cache value (ETag) corresponding to the argument (objectID) provided. // If a value is not found, then Get returns empty string ("") Get(objectID string) string // Set updates the value in the cache, returning a derp.Error in case there was a problem. Set(objectID string, value string) *derp.Error }
Cache maintains fast access to key/value pairs that are used to check ETags of incoming requests. By default, Presto uses a Null cache, that simply reports cache misses for every request. However, this can be extended by the user, with any external caching system that matches this interface.
var ETagCache Cache
type Collection ¶
type Collection struct {
// contains filtered or unexported fields
}
Collection provides all of the HTTP hanlers for a specific domain object, or collection of records
func NewCollection ¶
func NewCollection(router *echo.Echo, factory ServiceFactory, name string, prefix string) *Collection
NewCollection returns a fully populated Collection object
func (*Collection) Delete ¶
func (collection *Collection) Delete(roles ...RoleFunc) *Collection
Delete returns an HTTP handler that knows how to delete records from the collection
func (*Collection) Get ¶
func (collection *Collection) Get(roles ...RoleFunc) *Collection
Get returns an HTTP handler that knows how to retrieve a single record from the collection
func (*Collection) List ¶
func (collection *Collection) List(roles ...RoleFunc) *Collection
List returns an HTTP handler that knows how to list a series of records from the collection
func (*Collection) Method ¶
func (collection *Collection) Method()
func (*Collection) Patch ¶
func (collection *Collection) Patch(roles ...RoleFunc) *Collection
Patch returns an HTTP handler that knows how to update in the collection
func (*Collection) Post ¶
func (collection *Collection) Post(roles ...RoleFunc) *Collection
Post returns an HTTP handler that knows how to create new objects in the collection
func (*Collection) Put ¶
func (collection *Collection) Put(roles ...RoleFunc) *Collection
Put returns an HTTP handler that knows how to update in the collection
func (*Collection) WithScopes ¶ added in v0.2.0
func (collection *Collection) WithScopes(scopes ...ScopeFunc) *Collection
WithScopes replaces the default scope with a new list of ScopeFuncs
type Object ¶
type Object interface { // ID returns the primary key of the object ID() string // IsNew returns TRUE if the object has not yet been saved to the database IsNew() bool // SetCreated stamps the CreateDate and UpdateDate of the object, and makes a note SetCreated(comment string) // SetUpdated stamps the UpdateDate of the object, and makes a note SetUpdated(comment string) // SetDeleted marks the object virtually "deleted", and makes a note SetDeleted(comment string) // ETag returns a version-unique string that helps determine if an object has changed or not. ETag() string }
Object wraps all of the methods that a Domain Object must provide to Presto
type RoleFunc ¶
RoleFunc is a function signature that validates a user's permission to access a particular object
type Service ¶ added in v0.2.0
type Service interface { // NewObject creates a newly initialized object that is ready to use NewObject() Object // Load retrieves a single object from the database LoadObject(objectID string) (Object, *derp.Error) // Save inserts/updates a single object in the database SaveObject(object Object, comment string) *derp.Error // Delete removes a single object from the database DeleteObject(object Object, comment string) *derp.Error // Close cleans up any connections opened by the service. Close() }
Service defines all of the functions that a service must provide to work with Presto. It relies on the generic Object interface to load and save objects of any type. GenericServices will likely include additional business logic that is triggered when a domain object is created, edited, or deleted, but this is hidden from presto.
type ServiceFactory ¶
Factory is an interface for objects that generate service sessions. Each session represents a single HTTP request, which can potentially span multiple database calls. This gives the factory an opportunity to initialize a new database session for each HTTP request.