package rewriter import ( "forge.cadoles.com/cadoles/bouncer/internal/store" "github.com/mitchellh/mapstructure" "github.com/pkg/errors" ) type LayerOptions struct { MatchURLs []string `mapstructure:"matchURLs"` Rules Rules `mapstructure:"rules"` } type Rules struct { Request []string `mapstructure:"request"` Response []string `mapstructure:"response"` } func DefaultLayerOptions() LayerOptions { return LayerOptions{ MatchURLs: []string{"*"}, Rules: Rules{ Request: []string{}, Response: []string{}, }, } } func fromStoreOptions(storeOptions store.LayerOptions) (*LayerOptions, error) { layerOptions := DefaultLayerOptions() if err := FromStoreOptions(storeOptions, &layerOptions); err != nil { return nil, errors.WithStack(err) } return &layerOptions, nil } func FromStoreOptions(storeOptions store.LayerOptions, dest any) error { config := mapstructure.DecoderConfig{ Result: dest, ZeroFields: true, } decoder, err := mapstructure.NewDecoder(&config) if err != nil { return errors.WithStack(err) } if err := decoder.Decode(storeOptions); err != nil { return errors.WithStack(err) } return nil }