@@ -11,6 +11,7 @@ import (
11
11
koanfyaml "github.com/knadh/koanf/parsers/yaml"
12
12
"github.com/knadh/koanf/providers/env"
13
13
"github.com/knadh/koanf/providers/rawbytes"
14
+ "github.com/mitchellh/mapstructure"
14
15
"golang.org/x/text/cases"
15
16
"golang.org/x/text/language"
16
17
)
@@ -197,12 +198,12 @@ type IncomingWebhook struct {
197
198
198
199
// CloudSlackChannel contains configuration bindings per channel.
199
200
type CloudSlackChannel struct {
200
- ChannelBindingsByName `yaml:",inline"`
201
+ ChannelBindingsByName `yaml:",inline" mapstructure:",squash" `
201
202
202
203
// ChannelID is the Slack ID of the channel.
203
204
ChannelID string `yaml:"channelID"`
204
205
// Alias is an optional public alias for a private channel.
205
- Alias * string `yaml:"alias"`
206
+ Alias * string `yaml:"alias,omitempty "`
206
207
}
207
208
208
209
// ChannelBindingsByName contains configuration bindings per channel.
@@ -725,7 +726,20 @@ func LoadWithDefaults(configs [][]byte) (*Config, LoadWithDefaultsDetails, error
725
726
}
726
727
727
728
var cfg Config
728
- err = k .Unmarshal ("" , & cfg )
729
+ err = k .UnmarshalWithConf ("" , & cfg , koanf.UnmarshalConf {
730
+ DecoderConfig : & mapstructure.DecoderConfig {
731
+ Squash : true , // needed to properly unmarshal CloudSlack channel's ChannelBindingsByName
732
+
733
+ // also use defaults from koanf.UnmarshalWithConf
734
+ DecodeHook : mapstructure .ComposeDecodeHookFunc (
735
+ mapstructure .StringToTimeDurationHookFunc (),
736
+ mapstructure .StringToSliceHookFunc ("," ),
737
+ mapstructure .TextUnmarshallerHookFunc ()),
738
+ Metadata : nil ,
739
+ Result : & cfg ,
740
+ WeaklyTypedInput : true ,
741
+ },
742
+ })
729
743
if err != nil {
730
744
return nil , LoadWithDefaultsDetails {}, err
731
745
}
0 commit comments