Files
ziti/controller/models/validation.go
T
Paul Lorenz 6fdd5bcda5 Add support for multiple endpoints to services and sync model abstrac… (#53)
* Add support for multiple terminators to services and sync model abstractions with edge

* Add Snapshot to db.Db

* Make API friendly errors

* Add association querying. Consolidate Entity* interfaces
2020-03-19 13:23:16 -04:00

32 lines
610 B
Go

package models
import "fmt"
const (
maxFieldErrorValueLength = 20
)
type FieldError struct {
Reason string
FieldName string
FieldValue interface{}
}
func (fe FieldError) Error() string {
v := fe.FieldValue
if s, ok := fe.FieldValue.(string); ok {
if len(s) > maxFieldErrorValueLength {
v = s[0:maxFieldErrorValueLength] + "..."
}
}
return fmt.Sprintf("the value '%v' for '%s' is invalid: %s", v, fe.FieldName, fe.Reason)
}
func NewFieldError(reason, name string, value interface{}) *FieldError {
return &FieldError{
Reason: reason,
FieldName: name,
FieldValue: value,
}
}