我想在 NewNotifier 函数中使用 slacknotificationprovider 。我该怎么做。我还想在 newNotifier 函数中发送一个字符串(config.Cfg.SlackWebHookURL)。我应该怎么办?另外请给我推荐一些材料,以更深入地了解 golang 中的结构和接口。我还想知道为什么 ProviderType.Slack 没有定义,正如我在 SlackNotificationProvider 类型的 ProviderType 结构中提到的那样?谢谢。
type SlackNotificationProvider struct {
SlackWebHookURL string
PostPayload PostPayload
}
type ProviderType struct {
Slack SlackNotificationProvider
Discord DiscordNotificationProvider
}
type Notifier interface {
SendNotification() error
}
func NewNotifier(providerType ProviderType) Notifier {
if providerType == ProviderType.Slack {
return SlackNotificationProvider{
SlackWebHookURL: SlackWebHookURL,
}
} else if providerType == ProviderType.Discord {
return DiscordNotificationProvider{
DiscordWebHookURL: SlackWebHookURL + "/slack",
}
}
return nil
}
slackNotifier := NewNotifier(config.Cfg.SlackWebHookURL)
错误: 1. 无法使用 config.Cfg.SlackWebHookURL(字符串类型)作为 NewNotifiergo 参数中的 ProviderType 类型 2. ProviderType.Slack 未定义(ProviderType 类型没有 Slack 方法)go
qq_笑_17
相关分类