Documentation ¶
Index ¶
- Constants
- Variables
- func CheckPattern(key, value string) error
- func Error(err error, code int, msg, function string) error
- func LoadPatterns(fname string) (map[string]LexiconPattern, error)
- func Validate(r *http.Request) error
- func ValidatePostPayload(rec map[string]any) error
- func ValidateRecord(rec map[string]any) error
- type Lexicon
- type LexiconError
- type LexiconPattern
- type ObjectPattern
- type StrPattern
Constants ¶
const ( GenericErrorCode = iota + 10 // generic Lexicon error ReaderErrorCode // 11 reader error UnmarshalErrorCode // 12 unmarshal error MarshalErrorCode // 13 marshal error PatternErrorCode // 14 pattern error ValidateErrorCode // 15 validate error )
Lexicon Error codes provides static representation of Lexicon errors, they cover 1xx range
Variables ¶
var GenericErr = errors.New("lexicon error")
GenericErr represents generic lexicon error
var IntPattern = regexp.MustCompile(`^\d+$`)
var InvalidParamErr = errors.New("invalid parameter(s)")
InvalidParamErr represents generic error for invalid input parameter
var InvalidRequestErr = errors.New("invalid request error")
InvalidRequestErr represents generic invalid request error
var LexiconPatterns map[string]LexiconPattern
LexiconPatterns represents Lexicon patterns
var NotImplementedApiErr = errors.New("not implemented api error")
NotImplementedApiErr represents generic not implemented api error
var PatternErr = errors.New("invalid pattern")
PatterErr represents generic error for invalid input parameter
var RunRangePattern = regexp.MustCompile(`^\d+-\d+$`)
var UnixTimePattern = regexp.MustCompile(`^[1-9][0-9]{9}$`)
aux patterns
var ValidationErr = errors.New("validation error")
ValidationErr represents generic validation error
var Verbose int
Verbose defines module verbosity level
Functions ¶
func CheckPattern ¶
CheckPattern is a generic functino to check given key value within Lexicon map
func LoadPatterns ¶
func LoadPatterns(fname string) (map[string]LexiconPattern, error)
LoadPatterns loads Lexion patterns from given file the format of the file is a list of the following dicts: [ {"name": <name>, "patterns": [list of patterns], "length": int},...]
func ValidatePostPayload ¶
ValidatePostPayload function to validate POST request
func ValidateRecord ¶
ValidateRecord validates given JSON record
Types ¶
type Lexicon ¶
type Lexicon struct { Name string `json:"name"` Patterns []string `json:"patterns"` Length int `json:"length"` }
Lexicon represents single lexicon pattern structure
type LexiconError ¶
type LexiconError struct { Reason string `json:"reason"` // error string Message string `json:"message"` // additional message describing the issue Function string `json:"function"` // Lexicon function Code int `json:"code"` // Lexicon error code Stacktrace string `json:"stacktrace"` // Go stack trace }
LexiconError represents common structure for Lexicon errors
func (*LexiconError) Error ¶
func (e *LexiconError) Error() string
Error function implements details of Lexicon error message
func (*LexiconError) ErrorStacktrace ¶
func (e *LexiconError) ErrorStacktrace() string
ErrorStacktrace function implements details of Lexicon error message and stacktrace
func (*LexiconError) Explain ¶
func (e *LexiconError) Explain() string
Explain provides explanation about the error
type LexiconPattern ¶
LexiconPattern represents single lexicon compiled pattern structure
type ObjectPattern ¶
ObjectPattern represents interface to check different objects
type StrPattern ¶
StrPattern represents string object pattern
func (StrPattern) Check ¶
func (o StrPattern) Check(key string, val interface{}) error
Check implements ObjectPattern interface for StrPattern objects