Moving the Duration wrapper to it's own package to break import loops.

This commit is contained in:
gotyaoi 2015-10-16 23:10:14 -07:00 committed by Ellison Marks
parent d77cfd6ecc
commit 0299a17da1
6 changed files with 31 additions and 27 deletions

View File

@ -8,6 +8,7 @@ import (
"sync"
"time"
"github.com/influxdb/telegraf/duration"
"github.com/influxdb/telegraf/outputs"
"github.com/influxdb/telegraf/plugins"
@ -29,10 +30,10 @@ type runningPlugin struct {
type Agent struct {
// Interval at which to gather information
Interval Duration
Interval duration.Duration
// Interval at which to flush data
FlushInterval Duration
FlushInterval duration.Duration
// FlushRetries is the number of times to retry each data flush
FlushRetries int
@ -62,8 +63,8 @@ type Agent struct {
func NewAgent(config *Config) (*Agent, error) {
agent := &Agent{
Tags: make(map[string]string),
Interval: Duration{10 * time.Second},
FlushInterval: Duration{10 * time.Second},
Interval: duration.Duration{10 * time.Second},
FlushInterval: duration.Duration{10 * time.Second},
FlushRetries: 2,
UTC: true,
Precision: "s",

View File

@ -15,23 +15,6 @@ import (
"github.com/naoina/toml/ast"
)
// Duration just wraps time.Duration
type Duration struct {
time.Duration
}
// UnmarshalTOML parses the duration from the TOML config file
func (d *Duration) UnmarshalTOML(b []byte) error {
dur, err := time.ParseDuration(string(b[1 : len(b)-1]))
if err != nil {
return err
}
d.Duration = dur
return nil
}
// Config specifies the URL/user/password for the database that telegraf
// will be logging to, as well as all the plugins that the user has
// specified

20
duration/duration.go Normal file
View File

@ -0,0 +1,20 @@
package duration
import "time"
// Duration just wraps time.Duration
type Duration struct {
time.Duration
}
// UnmarshalTOML parses the duration from the TOML config file
func (d *Duration) UnmarshalTOML(b []byte) error {
dur, err := time.ParseDuration(string(b[1 : len(b)-1]))
if err != nil {
return err
}
d.Duration = dur
return nil
}

View File

@ -9,13 +9,13 @@ import (
"sort"
"github.com/influxdb/influxdb/client/v2"
t "github.com/influxdb/telegraf"
"github.com/influxdb/telegraf/duration"
"github.com/influxdb/telegraf/outputs"
)
type Datadog struct {
Apikey string
Timeout t.Duration
Timeout duration.Duration
apiUrl string
client *http.Client

View File

@ -9,7 +9,7 @@ import (
"strings"
"github.com/influxdb/influxdb/client/v2"
t "github.com/influxdb/telegraf"
"github.com/influxdb/telegraf/duration"
"github.com/influxdb/telegraf/outputs"
)
@ -22,7 +22,7 @@ type InfluxDB struct {
Database string
UserAgent string
Precision string
Timeout t.Duration
Timeout duration.Duration
conns []client.Client
}

View File

@ -11,7 +11,7 @@ import (
paho "git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.golang.git"
"github.com/influxdb/influxdb/client/v2"
t "github.com/influxdb/telegraf"
"github.com/influxdb/telegraf/duration"
"github.com/influxdb/telegraf/outputs"
)
@ -24,7 +24,7 @@ type MQTT struct {
Username string
Password string
Database string
Timeout t.Duration
Timeout duration.Duration
TopicPrefix string
Client *paho.Client