Files
fn-serverless/api/models/datastore.go
C Cirello a61c4dab78 Assert License (#224)
* license: assert license for Go code
* license: add in shell scripts
* license: assert license for Ruby code
* license: assert license to individual cases
* license: assert license to Dockerfile
2016-11-05 23:33:07 +01:00

49 lines
1.8 KiB
Go

// Copyright 2016 Iron.io
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package models
import "errors"
type Datastore interface {
GetApp(appName string) (*App, error)
GetApps(*AppFilter) ([]*App, error)
StoreApp(*App) (*App, error)
RemoveApp(appName string) error
GetRoute(appName, routePath string) (*Route, error)
GetRoutes(*RouteFilter) (routes []*Route, err error)
GetRoutesByApp(string, *RouteFilter) (routes []*Route, err error)
StoreRoute(*Route) (*Route, error)
RemoveRoute(appName, routePath string) error
// The following provide a generic key value store for arbitrary data, can be used by extensions to store extra data
// todo: should we namespace these by app? Then when an app is deleted, it can delete any of this extra data too.
Put([]byte, []byte) error
Get([]byte) ([]byte, error)
}
var (
ErrDatastoreEmptyAppName = errors.New("Missing app name")
ErrDatastoreEmptyRoutePath = errors.New("Missing route name")
ErrDatastoreEmptyApp = errors.New("Missing app")
ErrDatastoreEmptyRoute = errors.New("Missing route")
)
func ApplyRouteFilter(route *Route, filter *RouteFilter) bool {
return (filter.Path == "" || route.Path == filter.Path) &&
(filter.AppName == "" || route.AppName == filter.AppName) &&
(filter.Image == "" || route.Image == filter.Image)
}