mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
renamed route errors and added path validation
This commit is contained in:
@@ -3,6 +3,7 @@ package models
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"path"
|
||||||
|
|
||||||
apiErrors "github.com/go-openapi/errors"
|
apiErrors "github.com/go-openapi/errors"
|
||||||
)
|
)
|
||||||
@@ -28,29 +29,34 @@ type Route struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrRoutesValidationName = errors.New("Missing route Name")
|
ErrRoutesValidationMissingName = errors.New("Missing route Name")
|
||||||
ErrRoutesValidationImage = errors.New("Missing route Image")
|
ErrRoutesValidationMissingImage = errors.New("Missing route Image")
|
||||||
ErrRoutesValidationAppName = errors.New("Missing route AppName")
|
ErrRoutesValidationMissingAppName = errors.New("Missing route AppName")
|
||||||
ErrRoutesValidationPath = errors.New("Missing route Path")
|
ErrRoutesValidationMissingPath = errors.New("Missing route Path")
|
||||||
|
ErrRoutesValidationInvalidPath = errors.New("Invalid Path format")
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Route) Validate() error {
|
func (r *Route) Validate() error {
|
||||||
var res []error
|
var res []error
|
||||||
|
|
||||||
if r.Name == "" {
|
if r.Name == "" {
|
||||||
res = append(res, ErrRoutesValidationAppName)
|
res = append(res, ErrRoutesValidationMissingName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Image == "" {
|
if r.Image == "" {
|
||||||
res = append(res, ErrRoutesValidationImage)
|
res = append(res, ErrRoutesValidationMissingImage)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.AppName == "" {
|
if r.AppName == "" {
|
||||||
res = append(res, ErrRoutesValidationAppName)
|
res = append(res, ErrRoutesValidationMissingAppName)
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Path == "" {
|
if r.Path == "" {
|
||||||
res = append(res, ErrRoutesValidationPath)
|
res = append(res, ErrRoutesValidationMissingPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
if !path.IsAbs(r.Path) {
|
||||||
|
res = append(res, ErrRoutesValidationInvalidPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(res) > 0 {
|
if len(res) > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user