1
0
mirror of https://github.com/juanfont/headscale.git synced 2025-08-28 13:49:04 +02:00

We should be able to set the timezone in our config file.

This commit is contained in:
Deon Thomas 2022-05-15 15:21:46 -04:00
parent 3d03704d5a
commit 39544211a3
No known key found for this signature in database
GPG Key ID: 0FF7DAE12CA62D67
3 changed files with 26 additions and 8 deletions

View File

@ -71,10 +71,28 @@ func LoadConfig(path string) error {
viper.SetDefault("oidc.scope", []string{oidc.ScopeOpenID, "profile", "email"})
viper.SetDefault("oidc.strip_email_domain", true)
viper.SetDefault("TZ", "UTC")
if tz := os.Getenv("TZ"); tz != "" {
_, err := time.LoadLocation(tz)
if err == nil {
viper.SetDefault("TZ", tz)
}
}
if err := viper.ReadInConfig(); err != nil {
return fmt.Errorf("fatal error reading config file: %w", err)
}
if viper.GetString("time_zone") != "" {
_, err := time.LoadLocation(viper.GetString("time_zone"))
if err == nil {
viper.SetDefault("TZ", viper.GetString("time_zone"))
} else {
log.Warn().
Msg("Warning: invalid timzone, fallingback to UTC")
}
}
// Collect any validation errors and return them all at once
var errorText string
if (viper.GetString("tls_letsencrypt_hostname") != "") &&

View File

@ -37,14 +37,6 @@ func main() {
colors = false
}
viper.SetDefault("TZ", "UTC")
if tz := os.Getenv("TZ"); tz != "" {
_, err := time.LoadLocation(tz)
if err == nil {
viper.SetDefault("TZ", tz)
}
}
zerolog.TimestampFunc = headscale.NowFromTZEnv
log.Logger = log.Output(zerolog.ConsoleWriter{

View File

@ -16,6 +16,14 @@ server_url: http://127.0.0.1:8080
#
listen_addr: 0.0.0.0:8080
# Headscale uses UTC as it's default time zone
# you can override this by setting the TZ env
# variable. Additionally you can set your time
# zone here.
time_zone: UTC
# Address to listen to /metrics, you may want
# to keep this endpoint private to your internal
# network