github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/api/models/datastore.go (about)

     1  package models
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  )
     7  
     8  type Datastore interface {
     9  
    10  	// GetApp gets an App by name.
    11  	// Returns ErrDatastoreEmptyAppName for empty appName.
    12  	// Returns ErrAppsNotFound if no app is found.
    13  	GetApp(ctx context.Context, appName string) (*App, error)
    14  
    15  	// GetApps gets a slice of Apps, optionally filtered by name.
    16  	// Missing filter or empty name will match all Apps.
    17  	GetApps(ctx context.Context, filter *AppFilter) ([]*App, error)
    18  
    19  	// InsertApp inserts an App. Returns ErrDatastoreEmptyApp when app is nil, and
    20  	// ErrDatastoreEmptyAppName when app.Name is empty.
    21  	// Returns ErrAppsAlreadyExists if an App by the same name already exists.
    22  	InsertApp(ctx context.Context, app *App) (*App, error)
    23  
    24  	// UpdateApp updates an App's Config. Returns ErrDatastoreEmptyApp when app is nil, and
    25  	// ErrDatastoreEmptyAppName when app.Name is empty.
    26  	// Returns ErrAppsNotFound if an App is not found.
    27  	UpdateApp(ctx context.Context, app *App) (*App, error)
    28  
    29  	// RemoveApp removes the App named appName. Returns ErrDatastoreEmptyAppName if appName is empty.
    30  	// Returns ErrAppsNotFound if an App is not found.
    31  	//TODO remove routes automatically? #528
    32  	RemoveApp(ctx context.Context, appName string) error
    33  
    34  	// GetRoute looks up a matching Route for appName and the literal request route routePath.
    35  	// Returns ErrDatastoreEmptyAppName when appName is empty, and ErrDatastoreEmptyRoutePath when
    36  	// routePath is empty.
    37  	// Returns ErrRoutesNotFound when no matching route is found.
    38  	GetRoute(ctx context.Context, appName, routePath string) (*Route, error)
    39  
    40  	// GetRoutes gets a slice of Routes, optionally filtered by filter.
    41  	GetRoutes(ctx context.Context, filter *RouteFilter) (routes []*Route, err error)
    42  
    43  	// GetRoutesByApp gets a slice of routes for a appName, optionally filtering on filter (filter.AppName is ignored).
    44  	// Returns ErrDatastoreEmptyAppName if appName is empty.
    45  	GetRoutesByApp(ctx context.Context, appName string, filter *RouteFilter) (routes []*Route, err error)
    46  
    47  	// InsertRoute inserts a route. Returns ErrDatastoreEmptyRoute when route is nil, and ErrDatastoreEmptyAppName
    48  	// or ErrDatastoreEmptyRoutePath for empty AppName or Path.
    49  	// Returns ErrRoutesAlreadyExists if the exact route.Path already exists, or ErrRoutesCreate if a conflicting
    50  	// route already exists.
    51  	InsertRoute(ctx context.Context, route *Route) (*Route, error)
    52  
    53  	// UpdateRoute updates route's Config and Header fields. Returns ErrDatastoreEmptyRoute when route is nil, and
    54  	// ErrDatastoreEmptyAppName or ErrDatastoreEmptyRoutePath for empty AppName or Path.
    55  	UpdateRoute(ctx context.Context, route *Route) (*Route, error)
    56  
    57  	// RemoveRoute removes a route. Returns ErrDatastoreEmptyAppName when appName is empty, and
    58  	// ErrDatastoreEmptyRoutePath when routePath is empty. Returns ErrRoutesNotFound when no route exists.
    59  	RemoveRoute(ctx context.Context, appName, routePath string) error
    60  
    61  	// The following provide a generic key value store for arbitrary data, can be used by extensions to store extra data
    62  	// todo: should we namespace these by app? Then when an app is deleted, it can delete any of this extra data too.
    63  	Put(context.Context, []byte, []byte) error
    64  	Get(context.Context, []byte) ([]byte, error)
    65  }
    66  
    67  var (
    68  	ErrDatastoreEmptyAppName   = errors.New("Missing app name")
    69  	ErrDatastoreEmptyRoutePath = errors.New("Missing route name")
    70  	ErrDatastoreEmptyApp       = errors.New("Missing app")
    71  	ErrDatastoreEmptyRoute     = errors.New("Missing route")
    72  	ErrDatastoreEmptyKey       = errors.New("Missing key")
    73  )