observer/pkg/gelf_exporter/config.go
2024-04-26 15:09:54 +02:00

69 lines
1.4 KiB
Go

package gelfexporter
type config struct {
GelfUrl string
}
// 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
}
// WithWriter sets the export stream destination.
// func WithWriter(w io.Writer) Option {
// return writerOption{w}
// }
// type writerOption struct {
// W *gelf.Writer
// }
// func (o writerOption) apply(cfg config) config {
// cfg.Writer = o.W
// return cfg
// }
func WithGelfUrl(url string) Option {
return gelfUrlOption(url)
}
type gelfUrlOption string
func (o gelfUrlOption) apply(cfg config) config {
cfg.GelfUrl = string(o)
return cfg
}
// // WithPrettyPrint prettifies the emitted output.
// func WithPrettyPrint() Option {
// return prettyPrintOption(true)
// }
// type prettyPrintOption bool
// func (o prettyPrintOption) apply(cfg config) config {
// cfg.PrettyPrint = bool(o)
// return cfg
// }
// // WithoutTimestamps sets the export stream to not include timestamps.
// func WithoutTimestamps() Option {
// return timestampsOption(false)
// }
// type timestampsOption bool
// func (o timestampsOption) apply(cfg config) config {
// cfg.Timestamps = bool(o)
// return cfg
// }