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 DefaultScope(ctx echo.Context) (data.Expression, *derp.Error)
- func RequestInfo(context echo.Context) map[string]string
- func UseCache(cache Cache)
- func UseRouter(router *echo.Echo)
- func UseScopes(scopes ...ScopeFunc)
- 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(name string, handler echo.HandlerFunc)
- func (collection *Collection) Patch(roles ...RoleFunc) *Collection
- func (collection *Collection) Post(roles ...RoleFunc) *Collection
- func (collection *Collection) Put(roles ...RoleFunc) *Collection
- func (collection *Collection) UseCache(cache Cache) *Collection
- func (collection *Collection) UseScopes(scopes ...ScopeFunc) *Collection
- func (collection *Collection) UseToken(token string) *Collection
- type ETagger
- type RoleFunc
- type ScopeFunc
- type Service
- type ServiceFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultScope ¶ added in v0.2.11
func DefaultScope(ctx echo.Context) (data.Expression, *derp.Error)
DefaultScope maps all of the route parameters directly into a scope, matching the names used in the route itself. It is the default behavior for presto, and should serve most use cases.
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.
func UseCache ¶ added in v0.3.0
func UseCache(cache Cache)
UseCache sets the global cache for all presto endpoints.
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.
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(factory ServiceFunc, 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(name string, handler echo.HandlerFunc)
Method defines a custom "method"-style endpoint
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) UseCache ¶ added in v0.3.0
func (collection *Collection) UseCache(cache Cache) *Collection
UseCache adds a local ETag cache for this collection only
func (*Collection) UseScopes ¶ added in v0.3.0
func (collection *Collection) UseScopes(scopes ...ScopeFunc) *Collection
UseScopes replaces the default scope with a new list of ScopeFuncs
func (*Collection) UseToken ¶ added in v0.3.0
func (collection *Collection) UseToken(token string) *Collection
UseToken overrides the default "token" variable that is appended to all GET, PUT, PATCH, and DELETE routes, and is used as the unique identifier of the record being created, read, updated, or deleted.
type ETagger ¶ added in v0.2.8
type ETagger interface { // ETag returns a version-unique string that helps determine if an object has changed or not. ETag() string }
ETagger interface wraps the ETag function, which tells presto whether or not an object supports ETags. Presto uses ETags to automatically support optimistic locking of files, as well as saving time and bandwidth using 304: "Not Modified" responses when possible.
type RoleFunc ¶
RoleFunc is a function signature that validates a user's permission to access a particular object
type ScopeFunc ¶ added in v0.2.0
type ScopeFunc func(context echo.Context) (data.Expression, *derp.Error)
ScopeFunc is the function signature for a function that can limit database queries to a particular "scope". It inspects the provided context and returns criteria that will be passed to all database queries.
type Service ¶ added in v0.2.0
type Service interface { // NewObject creates a newly initialized object that is ready to use NewObject() data.Object // Load retrieves a single object from the database LoadObject(criteria data.Expression) (data.Object, *derp.Error) // Save inserts/updates a single object in the database SaveObject(object data.Object, comment string) *derp.Error // Delete removes a single object from the database DeleteObject(object data.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 ServiceFunc ¶ added in v0.2.0
type ServiceFunc func() Service
ServiceFunc is a function that can generate new services/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.