From 666e630d0076efd69f09e8c04b1cbcd580ff6baa Mon Sep 17 00:00:00 2001 From: gllm Date: Mon, 10 Apr 2023 12:44:53 +0200 Subject: [PATCH] feat(basic config): add milliseconds precision --- config.go | 12 +++++++----- fluent.go | 18 +++++------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/config.go b/config.go index 0e80ff5..a53d39e 100644 --- a/config.go +++ b/config.go @@ -11,16 +11,18 @@ type Config struct { // BasicConfig is used to configure the Writer with a basic configuration. type BasicConfig struct { - FluentHost string - FluentPort int + FluentHost string + FluentPort int + Milliseconds bool } // WithBasicConfig returns a function that can be used to configure the Writer with a basic configuration. -func WithBasicConfig(host string, port int) func(*Config) { +func WithBasicConfig(host string, port int, milliseconds bool) func(*Config) { return func(c *Config) { c.basicConfig = &BasicConfig{ - FluentHost: host, - FluentPort: port, + FluentHost: host, + FluentPort: port, + Milliseconds: milliseconds, } } } diff --git a/fluent.go b/fluent.go index b665b7b..9bec4df 100644 --- a/fluent.go +++ b/fluent.go @@ -23,24 +23,16 @@ func New(opts ...func(config *Config)) (*Writer, error) { opt(config) } - if config == nil { - return nil, ErrNoConfigProvided - } - var cfg *fluent.Config - if config.basicConfig != nil { cfg = &fluent.Config{ - FluentHost: config.basicConfig.FluentHost, - FluentPort: config.basicConfig.FluentPort, + FluentHost: config.basicConfig.FluentHost, + FluentPort: config.basicConfig.FluentPort, + SubSecondPrecision: config.basicConfig.Milliseconds, } - } - - if config.fluentConfig != nil { + } else if config.fluentConfig != nil { cfg = config.fluentConfig - } - - if cfg == nil { + } else { return nil, ErrNoConfigProvided }