Documentation ¶
Index ¶
- Constants
- func DetectedValueFromString(str string) interface{}
- type DirtyLogger
- func (dl *DirtyLogger) CreateCtxoutTracer() *DirtyLogger
- func (dl *DirtyLogger) CreateSimpleTracer() *DirtyLogger
- func (dl *DirtyLogger) GetTrace(find ...string) []string
- func (dl *DirtyLogger) Print(pattern ...string) string
- func (dl *DirtyLogger) SetAddTime(addTime bool) *DirtyLogger
- func (dl *DirtyLogger) SetTraceFn(traceFn TraceFn)
- func (dl *DirtyLogger) Trace(args ...interface{})
- type DirtyLoggerDef
- type LintChunk
- type LintMap
- type Linter
- func (l *Linter) Errors() []string
- func (l *Linter) GetDiff() (string, error)
- func (l *Linter) GetHighestIssueLevel() int
- func (l *Linter) GetIssue(level int, reportFn func(token *MatchToken))
- func (l *Linter) GetTrace(orFind ...string) string
- func (l *Linter) HasError() bool
- func (l *Linter) HasInfo() bool
- func (l *Linter) HasWarning() bool
- func (l *Linter) HaveParsingError() (string, bool)
- func (l *Linter) Infos() []string
- func (l *Linter) PrintIssues() string
- func (l *Linter) SetDirtyLogger(logger DirtyLoggerDef)
- func (l *Linter) Trace(arg ...interface{})
- func (l *Linter) Verify() error
- func (l *Linter) WalkIssues(hndlFn func(token *MatchToken, added bool))
- func (l *Linter) Warnings() []string
- type MatchToken
- type TraceFn
Constants ¶
const ( IssueLevelInfo = 2 IssueLevelWarn = 5 IssueLevelError = 10 )
const ( // -- info level -- Unset = -1 // the value is not set. the initial value. nothing was tryed to match PerfectMatch = 0 // the value and type matches. should most times not happen, because we compare the default values with actual values. so a diff is common ValueMatchButTypeDiffers = 1 // the value matches but in different type like "1.4" and 1.4 (valid because of yaml parser type conversion) ValueNotMatch = 2 // the value is not matching (still valid because of yaml parser type conversion. we compare the default values with actual values. so a diff is common) // -- warning level -- MissingEntry = 5 // the entry is missing. this entry is defined in struct but not in config. depends on the implementation if this is an issue. // -- error level -- WrongType = 11 // the type is wrong. different from the strct definition, and also no type conversion is possible UnknownEntry = 12 // the entry is is in the config but not in the struct IdentObject = 1 // the token is an object IdentArray = 2 // the token is an array IdentValue = 3 // the token is a value ValueString = 0 // the token is not Open or Close Object or Array and not KeyValue KeyValue = 1 // the token is a key value pair like "key: value" OpenObject = 2 // the token is an object like "{" CloseObject = 3 // the token is an object like "}" OpenArray = 4 // the token is an object like "[" CloseArray = 5 // the token is an object like "]" KeyedOpenObject = 6 // the token is an object like "key: {" KeyedOpenArray = 7 // the token is an object like "key: [" )
const (
DirtyLogMaxLen = 500
)
Variables ¶
This section is empty.
Functions ¶
func DetectedValueFromString ¶
func DetectedValueFromString(str string) interface{}
Types ¶
type DirtyLogger ¶
type DirtyLogger struct {
// contains filtered or unexported fields
}
func NewDirtyLogger ¶
func NewDirtyLogger() *DirtyLogger
func (*DirtyLogger) CreateCtxoutTracer ¶
func (dl *DirtyLogger) CreateCtxoutTracer() *DirtyLogger
func (*DirtyLogger) CreateSimpleTracer ¶
func (dl *DirtyLogger) CreateSimpleTracer() *DirtyLogger
func (*DirtyLogger) GetTrace ¶
func (dl *DirtyLogger) GetTrace(find ...string) []string
func (*DirtyLogger) Print ¶
func (dl *DirtyLogger) Print(pattern ...string) string
func (*DirtyLogger) SetAddTime ¶
func (dl *DirtyLogger) SetAddTime(addTime bool) *DirtyLogger
func (*DirtyLogger) SetTraceFn ¶
func (dl *DirtyLogger) SetTraceFn(traceFn TraceFn)
func (*DirtyLogger) Trace ¶
func (dl *DirtyLogger) Trace(args ...interface{})
type DirtyLoggerDef ¶
type LintChunk ¶
type LintChunk struct { ChunkNr int Removed []*MatchToken Added []*MatchToken }
type LintMap ¶
type LintMap struct {
Chunks []*LintChunk
}
func (*LintMap) GetTokensByTokenPath ¶
func (l *LintMap) GetTokensByTokenPath(fromToken *MatchToken) []*MatchToken
find tokens by keypath over all chunks
func (*LintMap) GetTokensFromSequence ¶
func (l *LintMap) GetTokensFromSequence(seq int) []*MatchToken
GetTokensFromSequence returns all tokens from the given sequence
func (*LintMap) GetTokensFromSequenceAndIndex ¶
func (l *LintMap) GetTokensFromSequenceAndIndex(seq int, index int) []*MatchToken
GetTokensFromSequenceAndIndex returns all tokens from the given sequence and index
type Linter ¶
type Linter struct {
// contains filtered or unexported fields
}
func NewLinter ¶
func NewLinter(config yacl.ConfigModel) *Linter
Create a new Linter. The config is the config model that we need to verify it must be loaded before, and it must be injected as pointer
func (*Linter) GetDiff ¶
GetDiff returns the diff between the config file and the structed config file. The diff is returned as string.
func (*Linter) GetHighestIssueLevel ¶
GetHighestIssueLevel returns the highest issue level found.
func (*Linter) GetIssue ¶
func (l *Linter) GetIssue(level int, reportFn func(token *MatchToken))
GetIssue will execute the reportFn for all tokens that have the same or higher level as the given level.
func (*Linter) HasError ¶
report if we found an issue with the config file, that should not be ignored.
func (*Linter) HasInfo ¶
report if we found an issue with the config file, that is most usual, like type conversion. (what is difficult to avoid)
func (*Linter) HasWarning ¶
report if we found an issue with the config file, that is not so important, but be warned.
func (*Linter) HaveParsingError ¶
if the lint fails and do not report any error, the config could be just invalid for structure parsing. this can happen while the config file is tryed to be loaded, but it is not readable. this can be the case if the config is injected with an reference of an pointer, or it is an array, a map[string]string or an interface{}. if this was happens, this function will return the reason why the parsing failed.
func (*Linter) PrintIssues ¶
PrintIssues will print the issues found in the diff. This is an report function and show any issue greater than 0.
func (*Linter) SetDirtyLogger ¶
func (l *Linter) SetDirtyLogger(logger DirtyLoggerDef)
func (*Linter) Trace ¶
func (l *Linter) Trace(arg ...interface{})
Trace is a helper function to trace the linter workflow. this might help to debug the linter.
func (*Linter) Verify ¶
Verify is the main function of the linter. It will verify the config file against the structed config file. It will return an error if the config file is not valid.
func (*Linter) WalkIssues ¶
func (l *Linter) WalkIssues(hndlFn func(token *MatchToken, added bool))
WalkIssues will execute the reportFn for all tokens that have the same or higher level as the given level.
type MatchToken ¶
type MatchToken struct { KeyWord string OrginKey string KeyPath string Value interface{} Type string Added bool SequenceNr int IndexNr int Status int PairToken *MatchToken ParentLint *LintMap TraceFunc func(args ...interface{}) }
func NewMatchToken ¶
func (*MatchToken) IsPair ¶
func (m *MatchToken) IsPair(token *MatchToken) bool
IsPair checks if the given token is a pair to this token it checks if the keyword is the same and the added flag is different if so it sets the pair token property and returns true
func (*MatchToken) IsValid ¶
func (m *MatchToken) IsValid() bool
IsValid checks if the token is valid and can be used for further processing
func (*MatchToken) ToIssueString ¶
func (m *MatchToken) ToIssueString() string
ToIssueString returns a string representation of the issue
func (*MatchToken) ToString ¶
func (m *MatchToken) ToString() string
func (*MatchToken) VerifyValue ¶
func (m *MatchToken) VerifyValue() int
VerifyValue checks if the value is matching the pair token if so it sets the status property and returns the status the status represents the issue level