lexicon

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
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

View Source
var GenericErr = errors.New("lexicon error")

GenericErr represents generic lexicon error

View Source
var IntPattern = regexp.MustCompile(`^\d+$`)
View Source
var InvalidParamErr = errors.New("invalid parameter(s)")

InvalidParamErr represents generic error for invalid input parameter

View Source
var InvalidRequestErr = errors.New("invalid request error")

InvalidRequestErr represents generic invalid request error

View Source
var LexiconPatterns map[string]LexiconPattern

LexiconPatterns represents Lexicon patterns

View Source
var NotImplementedApiErr = errors.New("not implemented api error")

NotImplementedApiErr represents generic not implemented api error

View Source
var PatternErr = errors.New("invalid pattern")

PatterErr represents generic error for invalid input parameter

View Source
var RunRangePattern = regexp.MustCompile(`^\d+-\d+$`)
View Source
var UnixTimePattern = regexp.MustCompile(`^[1-9][0-9]{9}$`)

aux patterns

View Source
var ValidationErr = errors.New("validation error")

ValidationErr represents generic validation error

View Source
var Verbose int

Verbose defines module verbosity level

Functions

func CheckPattern

func CheckPattern(key, value string) error

CheckPattern is a generic functino to check given key value within Lexicon map

func Error

func Error(err error, code int, msg, function string) error

helper function to create Lexicon error

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 Validate

func Validate(r *http.Request) error

Validate provides validation of all input parameters of HTTP request

func ValidatePostPayload

func ValidatePostPayload(rec map[string]any) error

ValidatePostPayload function to validate POST request

func ValidateRecord

func ValidateRecord(rec map[string]any) error

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

func (*Lexicon) String

func (r *Lexicon) String() string

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

type LexiconPattern struct {
	Lexicon  Lexicon
	Patterns []*regexp.Regexp
}

LexiconPattern represents single lexicon compiled pattern structure

type ObjectPattern

type ObjectPattern interface {
	Check(k string, v interface{}) error
}

ObjectPattern represents interface to check different objects

type StrPattern

type StrPattern struct {
	Patterns []*regexp.Regexp
	Len      int
}

StrPattern represents string object pattern

func (StrPattern) Check

func (o StrPattern) Check(key string, val interface{}) error

Check implements ObjectPattern interface for StrPattern objects

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL