Fixed lint issues and missing documentation

This commit is contained in:
bwilliams committed 2026-10-13 12:21:32 +01:00
1 parent 7fd321df97
commit 6e6dec68c0
34 files changed
+346 -156

No files matched your search

+18 -7
View File
@@ -11,16 +11,23 @@ import (
"go.yaml.in/yaml/v3"
)
// EnvPrefix prefixes environment variables that override configuration keys,
// e.g. JOBSEARCH_LOGGING_LEVEL for logging.level.
const EnvPrefix string = "JOBSEARCH"
// EtcConfigPath is searched for config.* when no config file is given, before
// the working directory.
const EtcConfigPath string = "/etc/job-search"
// Each field's cfg tag must match the section's JSCK* constant.
// JobSearchConfig is the application's whole configuration, one field per
// section. Each field's cfg tag must match the section's JSCK* constant.
type JobSearchConfig struct {
Logging JobSearchConfigLogging `cfg:"logging"`
Sources JobSearchConfigSources `cfg:"sources"`
}
// Default configuration, taken from the default struct tags
// LoadDefaultConfig sets Viper's defaults from the configuration's default
// struct tags.
func LoadDefaultConfig() {
var conf JobSearchConfig
if err := applyDefaults(&conf); err != nil {
@@ -29,6 +36,8 @@ func LoadDefaultConfig() {
LoadToViper(conf)
}
// ---------- Section methods (see Section) ----------
func (c JobSearchConfig) Map() map[string]any { return mapOf(c) }
func (c JobSearchConfig) Flatten() map[string]any { return flattenOf("", c) }
@@ -45,7 +54,8 @@ func (c *JobSearchConfig) SetValue(key string, value any) error {
return setValue(c, key, value)
}
// Utility method for loading a configuration from Viper
// LoadFromViper copies every key Viper knows that conf also has into conf.
// Unknown keys are skipped; invalid values are logged and ignored.
func LoadFromViper(conf *JobSearchConfig) {
keys := viper.AllKeys()
for idx := range keys {
@@ -71,7 +81,7 @@ func LoadFromViper(conf *JobSearchConfig) {
}
}
// Utility method for loading a configuration into Viper as defaults
// LoadToViper sets every key of conf as a Viper default.
func LoadToViper(conf JobSearchConfig) {
flatMap := conf.Flatten()
for key := range flatMap {
@@ -79,7 +89,8 @@ func LoadToViper(conf JobSearchConfig) {
}
}
// Converts configuration to a string in flat dotted format
// String formats the configuration one "key = value <type>" line per key, with
// dotted keys.
func (conf JobSearchConfig) String() string {
var sb strings.Builder
for k, v := range conf.Flatten() {
@@ -89,14 +100,14 @@ func (conf JobSearchConfig) String() string {
return sb.String()
}
// Converts configuration to JSON
// JSON formats the configuration as indented JSON.
func (conf JobSearchConfig) JSON() string {
confMap := conf.Map()
jbytes, _ := json.MarshalIndent(confMap, "", " ")
return string(jbytes)
}
// Converts configuration to YAML
// YAML formats the configuration as YAML.
func (conf JobSearchConfig) YAML() string {
confMap := conf.Map()
ybytes, _ := yaml.Marshal(confMap)