panel/shared/postgres.go

36 lines
821 B
Go
Raw Normal View History

2024-11-03 21:33:08 +01:00
package shared
import (
"github.com/spf13/viper"
2024-12-20 23:29:45 +01:00
"net"
2024-11-03 21:33:08 +01:00
"net/url"
2024-12-20 23:29:45 +01:00
"strconv"
"time"
2024-11-03 21:33:08 +01:00
)
func GetPostgresURI() string {
postgresURI := url.URL{
Scheme: "postgresql",
2024-12-20 23:29:45 +01:00
User: url.UserPassword(viper.GetString("omnibill.database.username"), viper.GetString("omnibill.database.password")),
Host: net.JoinHostPort(viper.GetString("omnibill.database.host"), strconv.Itoa(viper.GetInt("omnibill.database.port"))),
Path: viper.GetString("omnibill.database.database"),
2024-11-03 21:33:08 +01:00
}
values := postgresURI.Query()
values.Add("sslmode", "disable")
2024-12-20 23:29:45 +01:00
databaseTz := viper.GetString("database.tz")
if len(databaseTz) == 0 {
localTz, _ := time.Now().Zone()
values.Add("timezone", localTz)
}
2024-11-03 21:33:08 +01:00
values.Add("timezone", viper.GetString("database.tz"))
postgresURI.RawQuery = values.Encode()
return postgresURI.String()
}