mirror of
https://github.com/usual2970/certimate.git
synced 2025-06-08 05:29:51 +00:00
40 lines
813 B
Go
40 lines
813 B
Go
package domain
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
const CollectionNameSettings = "settings"
|
|
|
|
type Settings struct {
|
|
Meta
|
|
Name string `json:"name" db:"name"`
|
|
Content string `json:"content" db:"content"`
|
|
}
|
|
|
|
type NotifyTemplatesSettingsContent struct {
|
|
NotifyTemplates []NotifyTemplate `json:"notifyTemplates"`
|
|
}
|
|
|
|
type NotifyTemplate struct {
|
|
Subject string `json:"subject"`
|
|
Message string `json:"message"`
|
|
}
|
|
|
|
type NotifyChannelsSettingsContent map[string]map[string]any
|
|
|
|
func (s *Settings) GetNotifyChannelConfig(channel string) (map[string]any, error) {
|
|
conf := &NotifyChannelsSettingsContent{}
|
|
if err := json.Unmarshal([]byte(s.Content), conf); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
v, ok := (*conf)[channel]
|
|
if !ok {
|
|
return nil, fmt.Errorf("channel \"%s\" not found", channel)
|
|
}
|
|
|
|
return v, nil
|
|
}
|