mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
added wrapper on models; changed handlers; fixes
This commit is contained in:
@@ -3,27 +3,28 @@ package models
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
apiErrors "github.com/go-openapi/errors"
|
||||
)
|
||||
|
||||
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")
|
||||
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")
|
||||
ErrRoutesMissingNew = errors.New("Missing new route")
|
||||
)
|
||||
|
||||
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,omitempty"`
|
||||
ContainerPath string `json:"container_path,omitempty"`
|
||||
Headers http.Header `json:"headers,omitempty"`
|
||||
Name string `json:"name"`
|
||||
AppName string `json:"appname"`
|
||||
Path string `json:"path"`
|
||||
Image string `json:"image"`
|
||||
Headers http.Header `json:"headers,omitempty"`
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -34,20 +35,26 @@ var (
|
||||
)
|
||||
|
||||
func (r *Route) Validate() error {
|
||||
var res []error
|
||||
|
||||
if r.Name == "" {
|
||||
return ErrRoutesValidationName
|
||||
res = append(res, ErrRoutesValidationAppName)
|
||||
}
|
||||
|
||||
if r.Image == "" {
|
||||
return ErrRoutesValidationImage
|
||||
res = append(res, ErrRoutesValidationImage)
|
||||
}
|
||||
|
||||
if r.AppName == "" {
|
||||
return ErrRoutesValidationAppName
|
||||
res = append(res, ErrRoutesValidationAppName)
|
||||
}
|
||||
|
||||
if r.Path == "" {
|
||||
return ErrRoutesValidationPath
|
||||
res = append(res, ErrRoutesValidationPath)
|
||||
}
|
||||
|
||||
if len(res) > 0 {
|
||||
return apiErrors.CompositeValidationError(res...)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user