mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
refactoring API and added dbs: postgres, bolt
This commit is contained in:
22
api/models/app.go
Normal file
22
api/models/app.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package models
|
||||
|
||||
import "errors"
|
||||
|
||||
type Apps []App
|
||||
|
||||
var (
|
||||
ErrAppsCreate = errors.New("Could not create app")
|
||||
ErrAppsUpdate = errors.New("Could not update app")
|
||||
ErrAppsRemoving = errors.New("Could not remove app from datastore")
|
||||
ErrAppsGet = errors.New("Could not get app from datastore")
|
||||
ErrAppsList = errors.New("Could not list apps from datastore")
|
||||
ErrAppsNotFound = errors.New("App not found")
|
||||
)
|
||||
|
||||
type App struct {
|
||||
Name string `json:"name"`
|
||||
Routes Routes `json:"routes"`
|
||||
}
|
||||
|
||||
type AppFilter struct {
|
||||
}
|
||||
21
api/models/datastore.go
Normal file
21
api/models/datastore.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package models
|
||||
|
||||
type Datastore interface {
|
||||
GetApp(appName string) (*App, error)
|
||||
GetApps(*AppFilter) ([]*App, error)
|
||||
StoreApp(*App) (*App, error)
|
||||
RemoveApp(appName string) error
|
||||
|
||||
GetRoute(appName, routeName string) (*Route, error)
|
||||
GetRoutes(*RouteFilter) (routes []*Route, err error)
|
||||
StoreRoute(*Route) (*Route, error)
|
||||
RemoveRoute(appName, routeName string) error
|
||||
}
|
||||
|
||||
func ApplyAppFilter(app *App, filter *AppFilter) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func ApplyRouteFilter(route *Route, filter *RouteFilter) bool {
|
||||
return true
|
||||
}
|
||||
15
api/models/error.go
Normal file
15
api/models/error.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package models
|
||||
|
||||
import "errors"
|
||||
|
||||
type Error struct {
|
||||
Error *ErrorBody `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
func (m *Error) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidJSON = errors.New("Could not create app")
|
||||
)
|
||||
11
api/models/error_body.go
Normal file
11
api/models/error_body.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package models
|
||||
|
||||
type ErrorBody struct {
|
||||
Fields string `json:"fields,omitempty"`
|
||||
Message string `json:"message,omitempty"`
|
||||
}
|
||||
|
||||
// Validate validates this error body
|
||||
func (m *ErrorBody) Validate() error {
|
||||
return nil
|
||||
}
|
||||
31
api/models/route.go
Normal file
31
api/models/route.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrRoutesCreate = errors.New("Could not create route")
|
||||
ErrRoutesUpdate = errors.New("Could not update route")
|
||||
ErrRoutesRemoving = errors.New("Could not remove route from datastore")
|
||||
ErrRoutesGet = errors.New("Could not get route from datastore")
|
||||
ErrRoutesList = errors.New("Could not list routes from datastore")
|
||||
ErrRoutesNotFound = errors.New("Route not found")
|
||||
)
|
||||
|
||||
type Routes []Route
|
||||
|
||||
type Route struct {
|
||||
Name string `json:"name"`
|
||||
AppName string `json:"appname"`
|
||||
Path string `json:"path"`
|
||||
Image string `json:"image"`
|
||||
Type string `json:"type"`
|
||||
ContainerPath string `json:"container_path"`
|
||||
Headers http.Header `json:"headers"`
|
||||
}
|
||||
|
||||
type RouteFilter struct {
|
||||
AppName string
|
||||
}
|
||||
Reference in New Issue
Block a user