✨ Allow formatters to use sub-config with their own config structs
This commit is contained in:
parent
9f05f933dd
commit
6c6a959af4
4 changed files with 21 additions and 21 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue