Don't rely exclusively on /etc/timezone
This commit is contained in:
parent
141a60c1d1
commit
1df1ba8996
6 changed files with 47 additions and 11 deletions
|
|
@ -17,6 +17,7 @@ func (c *Config) declareFlags() {
|
|||
flag.StringVar(&c.ActionsDir, "actions-dir", c.ActionsDir, "Path to the directory containing the actions")
|
||||
flag.StringVar(&c.RoutinesDir, "routines-dir", c.RoutinesDir, "Path to the directory containing the routines")
|
||||
flag.IntVar(&c.SampleRate, "samplerate", c.SampleRate, "Samplerate for unifying output stream")
|
||||
flag.Var(&c.Timezone, "timezone", "Timezone to use when dealing with times")
|
||||
|
||||
// Others flags are declared in some other files when they need specials configurations
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ type Config struct {
|
|||
ActionsDir string
|
||||
RoutinesDir string
|
||||
|
||||
Timezone Timezone
|
||||
SampleRate int
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package config
|
|||
import (
|
||||
"encoding/base64"
|
||||
"net/url"
|
||||
"time"
|
||||
)
|
||||
|
||||
type JWTSecretKey []byte
|
||||
|
|
@ -42,3 +43,33 @@ func (i *URL) Set(value string) error {
|
|||
i.URL = u
|
||||
return nil
|
||||
}
|
||||
|
||||
type Timezone struct {
|
||||
tz *time.Location
|
||||
}
|
||||
|
||||
func (tz *Timezone) GetLocation() *time.Location {
|
||||
if tz.tz != nil {
|
||||
return tz.tz
|
||||
} else {
|
||||
return time.Local
|
||||
}
|
||||
}
|
||||
|
||||
func (tz *Timezone) String() string {
|
||||
if tz.tz != nil {
|
||||
return tz.tz.String()
|
||||
} else {
|
||||
return time.Local.String()
|
||||
}
|
||||
}
|
||||
|
||||
func (tz *Timezone) Set(value string) error {
|
||||
newtz, err := time.LoadLocation(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
tz.tz = newtz
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue