config

package
v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultWechatConfig defines default values for wechat configurations.
	DefaultWechatConfig = WechatConfig{
		Message: `{{ template "wechat.default.message" . }}`,
		ToUser:  `{{ template "wechat.default.to_user" . }}`,
		ToParty: `{{ template "wechat.default.to_party" . }}`,
		ToTag:   `{{ template "wechat.default.to_tag" . }}`,
		AgentID: `{{ template "wechat.default.agent_id" . }}`,
	}
	// DefaultDingtalkConfig ......
	DefaultDingtalkConfig = DingtalkConfig{
		Markdown: &DingtalkMarkdown{
			Title: `{{ template "dingtalk.default.title" . }}`,
			Text:  `{{ template "dingtalk.default.content" . }}`,
		},
	}
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Global    *GlobalConfig `yaml:"global,omitempty" json:"global,omitempty"`
	Receivers []*Receiver   `yaml:"receivers,omitempty" json:"receivers,omitempty"`
	Templates []string      `yaml:"templates" json:"templates"`
	S3        *S3Config     `yaml:"s3" json:"s3"`
	// contains filtered or unexported fields
}

Config 整个应用最顶层的配置文件

func Load

func Load(s string) (*Config, error)

Load parses the YAML input s into a Config.

func LoadFile

func LoadFile(filename string) (*Config, error)

LoadFile parses the given YAML file into a Config.

func (Config) GetReceiver

func (c Config) GetReceiver(name string) *Receiver

func (Config) String

func (c Config) String() string

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for Config.

type DingtalkAt

type DingtalkAt struct {
	AtMobiles []string `yaml:"atMobiles" json:"atMobiles,omitempty"`
	IsAtAll   bool     `yaml:"isAtAll" json:"isAtAll,omitempty"`
}

type DingtalkConfig

type DingtalkConfig struct {
	HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`

	APISecret Secret `yaml:"api_secret,omitempty" json:"api_secret,omitempty"`
	APIToken  Secret `yaml:"api_token,omitempty" json:"api_token,omitempty"`
	APIURL    *URL   `yaml:"api_url,omitempty" json:"api_url,omitempty"`

	Text        *DingtalkText     `yaml:"text,omitempty" json:"text,omitempty"`
	Markdown    *DingtalkMarkdown `yaml:"markdown,omitempty" json:"markdown,omitempty"`
	At          *DingtalkAt       `yaml:"at,omitempty" json:"at,omitempty"`
	MessageType string            `yaml:"message_type,omitempty" json:"message_type,omitempty"`
}

func (*DingtalkConfig) UnmarshalYAML

func (c *DingtalkConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type DingtalkMarkdown

type DingtalkMarkdown struct {
	Title string `yaml:"title" json:"title"`
	Text  string `yaml:"text" json:"text"`
}

type DingtalkText

type DingtalkText struct {
	Title   string `yaml:"title" json:"title"`
	Content string `yaml:"content" json:"content"`
}

type GlobalConfig

type GlobalConfig struct {
	ExternalURL      *URL  `yaml:"external_url,omitempty" json:"external_url,omitempty"`
	MetricResolution int64 `yaml:"metric_resolution,omitempty" json:"metric_resolution,omitempty"`
	PrometheusURL    *URL  `yaml:"prometheus_url" json:"prometheus_url"` // 配置 prometheus 地址,方便获取监控图表数据

	HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`

	WeChatAPIURL    *URL   `yaml:"wechat_api_url,omitempty" json:"wechat_api_url,omitempty"`
	WeChatAPISecret Secret `yaml:"wechat_api_secret,omitempty" json:"wechat_api_secret,omitempty"`
	WeChatAPICorpID Secret `yaml:"wechat_api_corp_id,omitempty" json:"wechat_api_corp_id,omitempty"`

	DingTalkAPIURL    *URL   `yaml:"dingtalk_api_url,omitempty" json:"dingtalk_api_url,omitempty"`
	DingTalkAPIToken  Secret `yaml:"dingtalk_api_token,omitempty" json:"dingtalk_api_token,omitempty"`
	DingTalkAPISecret Secret `yaml:"dingtalk_api_secret,omitempty" json:"dingtalk_api_secret,omitempty"`
}

GlobalConfig 定义全局配置参数

func DefaultGlobalConfig

func DefaultGlobalConfig() GlobalConfig

DefaultGlobalConfig 返回带默认值的全局配置

func (*GlobalConfig) UnmarshalYAML

func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for GlobalConfig.

type HostPort

type HostPort struct {
	Host string
	Port string
}

HostPort represents a "host:port" network address.

func (HostPort) MarshalJSON

func (hp HostPort) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for HostPort.

func (HostPort) MarshalYAML

func (hp HostPort) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for HostPort.

func (HostPort) String

func (hp HostPort) String() string

func (*HostPort) UnmarshalJSON

func (hp *HostPort) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for HostPort.

func (*HostPort) UnmarshalYAML

func (hp *HostPort) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for HostPort.

type MatchRegexps

type MatchRegexps map[string]Regexp

MatchRegexps represents a map of Regexp.

func (*MatchRegexps) UnmarshalYAML

func (m *MatchRegexps) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for MatchRegexps.

type Receiver

type Receiver struct {
	// A unique identifier for this receiver.
	Name string `yaml:"name" json:"name"`

	//EmailConfigs     []*EmailConfig     `yaml:"email_configs,omitempty" json:"email_configs,omitempty"`
	WechatConfig   *WechatConfig   `yaml:"wechat_config,omitempty" json:"wechat_config,omitempty"`
	DingtalkConfig *DingtalkConfig `yaml:"dingtalk_config,omitempty" json:"dingtalk_config,omitempty"`
}

Receiver configuration provides configuration on how to contact a receiver.

func (*Receiver) UnmarshalYAML

func (c *Receiver) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for Receiver.

type Regexp

type Regexp struct {
	*regexp.Regexp
	// contains filtered or unexported fields
}

Regexp encapsulates a regexp.Regexp and makes it YAML marshalable.

func (Regexp) MarshalJSON

func (re Regexp) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Regexp.

func (Regexp) MarshalYAML

func (re Regexp) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for Regexp.

func (*Regexp) UnmarshalJSON

func (re *Regexp) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for Regexp

func (*Regexp) UnmarshalYAML

func (re *Regexp) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for Regexp.

type S3Config

type S3Config struct {
	AccessKey Secret `yaml:"access_key" json:"access_key"`
	SecretKey Secret `yaml:"secret_key" json:"secret_key"`
	Endpoint  string `yaml:"endpoint" json:"endpoint"`
	Region    string `yaml:"region" json:"region"`
	Bucket    string `yaml:"bucket" json:"bucket"`
}

type Secret

type Secret string

Secret is a string that must not be revealed on marshaling.

func (Secret) MarshalJSON

func (s Secret) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Secret.

func (Secret) MarshalYAML

func (s Secret) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for Secret.

func (*Secret) UnmarshalYAML

func (s *Secret) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for Secret.

type SecretURL

type SecretURL URL

SecretURL is a URL that must not be revealed on marshaling.

func (SecretURL) MarshalJSON

func (s SecretURL) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for SecretURL.

func (SecretURL) MarshalYAML

func (s SecretURL) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for SecretURL.

func (*SecretURL) UnmarshalJSON

func (s *SecretURL) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Marshaler interface for SecretURL.

func (*SecretURL) UnmarshalYAML

func (s *SecretURL) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for SecretURL.

type URL

type URL struct {
	*url.URL
}

URL is a custom type that represents an HTTP or HTTPS URL and allows validation at configuration load time.

func (*URL) Copy

func (u *URL) Copy() *URL

Copy makes a deep-copy of the struct.

func (URL) MarshalJSON

func (u URL) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for URL.

func (URL) MarshalYAML

func (u URL) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface for URL.

func (*URL) UnmarshalJSON

func (u *URL) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Marshaler interface for URL.

func (*URL) UnmarshalYAML

func (u *URL) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface for URL.

type WechatConfig

type WechatConfig struct {
	//NotifierConfig `yaml:",inline" json:",inline"`
	HTTPConfig *commoncfg.HTTPClientConfig `yaml:"http_config,omitempty" json:"http_config,omitempty"`

	APISecret    Secret              `yaml:"api_secret,omitempty" json:"api_secret,omitempty"`
	CorpID       Secret              `yaml:"corp_id,omitempty" json:"corp_id,omitempty"`
	Message      string              `yaml:"message,omitempty" json:"message,omitempty"`
	TemplateCard *WechatTemplateCard `yaml:"template_card,omitempty" json:"template_card,omitempty"`
	APIURL       *URL                `yaml:"api_url,omitempty" json:"api_url,omitempty"`
	ToUser       string              `yaml:"to_user,omitempty" json:"to_user,omitempty"`
	ToParty      string              `yaml:"to_party,omitempty" json:"to_party,omitempty"`
	ToTag        string              `yaml:"to_tag,omitempty" json:"to_tag,omitempty"`
	AgentID      string              `yaml:"agent_id,omitempty" json:"agent_id,omitempty"`
	MessageType  string              `yaml:"message_type,omitempty" json:"message_type,omitempty"`
}

WechatConfig configures notifications via Wechat.

func (*WechatConfig) UnmarshalYAML

func (c *WechatConfig) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

type WechatTemplateCard

type WechatTemplateCard struct {
	Title       string `yaml:"title" json:"title"`
	Description string `yaml:"desc" json:"desc"`
	ImageURL    string `yaml:"image_url" json:"image_url"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL