Refactored main.go into cmd/jobsearch/main.go (in case separate commands are introduced later) which has required the options mechanism to change slightly as well as the logging.
This commit is contained in:
1 parent
de3ebf68c5
commit
6436253629
14 files changed
+273
-224
No files matched your search
@@ -24,6 +24,7 @@ import (
|
||||
|
||||
type JobSearchConfigLogging struct {
|
||||
Level string
|
||||
File string
|
||||
}
|
||||
|
||||
// Default configuration
|
||||
@@ -37,6 +38,7 @@ func defaultConfigLogging() JobSearchConfigLogging {
|
||||
func (conf JobSearchConfigLogging) Map() map[string]any {
|
||||
return map[string]any{
|
||||
"level": conf.Level,
|
||||
"file": conf.File,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,6 +57,8 @@ func (c JobSearchConfigLogging) TypeOf(key string) (reflect.Kind, error) {
|
||||
switch key {
|
||||
case "level":
|
||||
return reflect.String, nil
|
||||
case "file":
|
||||
return reflect.String, nil
|
||||
default:
|
||||
return reflect.Invalid, errors.New("unknown configuration key")
|
||||
}
|
||||
@@ -65,6 +69,8 @@ func (c JobSearchConfigLogging) ValueOf(key string) (any, error) {
|
||||
switch key {
|
||||
case "level":
|
||||
return c.Level, nil
|
||||
case "file":
|
||||
return c.File, nil
|
||||
default:
|
||||
return "", errors.New("unknown configuration key")
|
||||
}
|
||||
@@ -82,12 +88,15 @@ func (c *JobSearchConfigLogging) SetValue(key string, value any) error {
|
||||
return errors.New(
|
||||
"invalid log level. Must be one of: debug, info, warn, error")
|
||||
}
|
||||
case "file":
|
||||
c.File = value.(string)
|
||||
default:
|
||||
return errors.New("unknown configuration key")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Utility methods for converting level strings to slog levels
|
||||
func ConfigLevelToLogLevel(level string) slog.Level {
|
||||
switch level {
|
||||
case "debug":
|
||||
@@ -102,7 +111,6 @@ func ConfigLevelToLogLevel(level string) slog.Level {
|
||||
return 99
|
||||
}
|
||||
}
|
||||
|
||||
func (c *JobSearchConfigLogging) LogLevel() slog.Level {
|
||||
return ConfigLevelToLogLevel(c.Level)
|
||||
}
|
||||
Reference in new issue
Block a user