Naming, layout and comments: descriptive full-word names, one item per line in wrapped calls and literals, and doc comments on exported names

Short and single-letter names in application code become full words (tests
keep theirs). Wrapped calls, signatures and composite literals put one item
per line, and one-line function bodies are expanded. Exported names and
groups of constants get doc comments, and comments refer to the renamed
identifiers.
This commit is contained in:
bwilliams committed 2026-10-15 16:12:56 +01:00
1 parent 043e307663
commit 465358609a
78 files changed
+2374 -1402

No files matched your search

+19 -19
View File
@@ -62,8 +62,8 @@ func (c *JobSearchConfig) SetValue(key string, value any) error {
// Unknown keys are skipped; invalid values are logged and ignored.
func LoadFromViper(conf *JobSearchConfig) {
keys := viper.AllKeys()
for idx := range keys {
key := keys[idx]
for i := range keys {
key := keys[i]
keyType, _ := conf.TypeOf(key)
if keyType == reflect.Invalid {
continue
@@ -94,15 +94,15 @@ func viperValue(key string, kind reflect.Kind) (value any, ok bool) {
// SetValue to split on commas; GetStringSlice would split it on
// spaces. A list of objects (a list of sections) is passed on as it
// is, as GetStringSlice would flatten it.
switch v := viper.Get(key).(type) {
switch value := viper.Get(key).(type) {
case string:
return v, true
return value, true
case []map[string]any: // as LoadToViper sets it
return v, true
return value, true
case []any:
if len(v) > 0 {
if _, ok := v[0].(map[string]any); ok {
return v, true
if len(value) > 0 {
if _, ok := value[0].(map[string]any); ok {
return value, true
}
}
}
@@ -121,26 +121,26 @@ func LoadToViper(conf JobSearchConfig) {
// String formats the configuration one "key = value <type>" line per key, with
// dotted keys, sorted by key.
func (conf JobSearchConfig) String() string {
var sb strings.Builder
flat := conf.Flatten()
for _, k := range slices.Sorted(maps.Keys(flat)) {
typ, _ := conf.TypeOf(k)
fmt.Fprint(&sb, k, " = ", flat[k], " <", typ, ">\n")
func (c JobSearchConfig) String() string {
var builder strings.Builder
flat := c.Flatten()
for _, key := range slices.Sorted(maps.Keys(flat)) {
kind, _ := c.TypeOf(key)
fmt.Fprint(&builder, key, " = ", flat[key], " <", kind, ">\n")
}
return sb.String()
return builder.String()
}
// JSON formats the configuration as indented JSON.
func (conf JobSearchConfig) JSON() string {
confMap := conf.Map()
func (c JobSearchConfig) JSON() string {
confMap := c.Map()
jbytes, _ := json.MarshalIndent(confMap, "", " ")
return string(jbytes)
}
// YAML formats the configuration as YAML.
func (conf JobSearchConfig) YAML() string {
confMap := conf.Map()
func (c JobSearchConfig) YAML() string {
confMap := c.Map()
ybytes, _ := yaml.Marshal(confMap)
return string(ybytes)
}