2024-04-26 13:09:54 +00:00
|
|
|
package gelfexporter
|
|
|
|
|
|
|
|
type config struct {
|
|
|
|
GelfUrl string
|
2024-04-30 10:41:05 +00:00
|
|
|
AppName string
|
2024-04-26 13:09:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// newConfig creates a validated Config configured with options.
|
|
|
|
func newConfig(options ...Option) (config, error) {
|
|
|
|
cfg := config{}
|
|
|
|
for _, opt := range options {
|
|
|
|
cfg = opt.apply(cfg)
|
|
|
|
}
|
|
|
|
return cfg, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Option sets the value of an option for a Config.
|
|
|
|
type Option interface {
|
|
|
|
apply(config) config
|
|
|
|
}
|
|
|
|
|
|
|
|
func WithGelfUrl(url string) Option {
|
|
|
|
return gelfUrlOption(url)
|
|
|
|
}
|
|
|
|
|
|
|
|
type gelfUrlOption string
|
|
|
|
|
|
|
|
func (o gelfUrlOption) apply(cfg config) config {
|
|
|
|
cfg.GelfUrl = string(o)
|
|
|
|
return cfg
|
|
|
|
}
|
|
|
|
|
2024-04-30 10:41:05 +00:00
|
|
|
func WithAppName(url string) Option {
|
|
|
|
return appName(url)
|
|
|
|
}
|
2024-04-26 13:09:54 +00:00
|
|
|
|
2024-04-30 10:41:05 +00:00
|
|
|
type appName string
|
2024-04-26 13:09:54 +00:00
|
|
|
|
2024-04-30 10:41:05 +00:00
|
|
|
func (o appName) apply(cfg config) config {
|
|
|
|
cfg.AppName = string(o)
|
|
|
|
return cfg
|
|
|
|
}
|