Allow formatters to use sub-config with their own config structs

This commit is contained in:
Dan Jones 2026-03-08 23:29:36 -05:00
commit 6c6a959af4
4 changed files with 21 additions and 21 deletions

View file

@ -3,23 +3,24 @@ package formatters
import (
"bytes"
"encoding/json"
"fmt"
"time"
"codeberg.org/danjones000/my-log/models"
"github.com/spf13/viper"
)
func newJson(ff map[string]any) (Formatter, error) {
prettyPrint := false
if jf, ok := ff["json"].(map[string]any); ok {
if pp, ok := jf["pretty_print"].(bool); ok {
prettyPrint = pp
}
func newJson(ff *viper.Viper) (Formatter, error) {
js := new(Json)
err := ff.Unmarshal(js)
if err != nil {
return nil, fmt.Errorf("failed to get json config: %w", err)
}
return &Json{prettyPrint}, nil
return js, nil
}
type Json struct {
prettPrint bool
prettPrint bool `mapstructure:"pretty_print"`
}
func (js *Json) Name() string {