forked from quay/clair
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
config: implement and use validator interface
Signed-off-by: Hank Donnay <[email protected]>
- Loading branch information
Showing
21 changed files
with
443 additions
and
247 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package config | ||
|
||
import ( | ||
"encoding" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
//go:generate stringer -type Mode,LogLevel -linecomment -output enums_string.go | ||
|
||
// A Mode is an operating mode recognized by Clair. | ||
// | ||
// This is not directly settable by serializing into a Config object. | ||
type Mode int | ||
|
||
// Clair modes, with their string representations as the comments. | ||
const ( | ||
ComboMode Mode = iota // combo | ||
IndexerMode // indexer | ||
MatcherMode // matcher | ||
NotifierMode // notifier | ||
) | ||
|
||
// ParseMode returns a mode for the given string. | ||
// | ||
// The passed string is case-insensitive. | ||
func ParseMode(s string) (Mode, error) { | ||
for i, lim := 0, len(_Mode_index); i < lim; i++ { | ||
m := Mode(i) | ||
if strings.EqualFold(s, m.String()) { | ||
return m, nil | ||
} | ||
} | ||
return Mode(-1), fmt.Errorf(`unknown mode %q`, s) | ||
} | ||
|
||
// A LogLevel is a log level recognized by Clair. | ||
// | ||
// The zero value is "info". | ||
type LogLevel int | ||
|
||
// The recognized log levels, with their string representations as the comments. | ||
// | ||
// NB "Fatal" and "Panic" are not used in clair or claircore, and will result in | ||
// almost no logging. | ||
const ( | ||
InfoLog LogLevel = iota // info | ||
DebugColorLog // debug-color | ||
DebugLog // debug | ||
WarnLog // warn | ||
ErrorLog // error | ||
FatalLog // fatal | ||
PanicLog // panic | ||
) | ||
|
||
// ParseLogLevel returns the log lever for the given string. | ||
// | ||
// The passed string is case-insensitive. | ||
func ParseLogLevel(s string) (LogLevel, error) { | ||
for i, lim := 0, len(_LogLevel_index); i < lim; i++ { | ||
l := LogLevel(i) | ||
if strings.EqualFold(s, l.String()) { | ||
return l, nil | ||
} | ||
} | ||
return LogLevel(-1), fmt.Errorf(`unknown log level %q`, s) | ||
} | ||
|
||
// UnmarshalText implements encoding.TextUnmarshaler. | ||
func (l *LogLevel) UnmarshalText(b []byte) (err error) { | ||
*l, err = ParseLogLevel(string(b)) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// Assert LogLevel implements TextUnmarshaler. | ||
var _ encoding.TextUnmarshaler = (*LogLevel)(nil) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.