35 lines
821 B
Go
35 lines
821 B
Go
package shared
|
|
|
|
import (
|
|
"github.com/spf13/viper"
|
|
"net"
|
|
"net/url"
|
|
"strconv"
|
|
"time"
|
|
)
|
|
|
|
func GetPostgresURI() string {
|
|
postgresURI := url.URL{
|
|
Scheme: "postgresql",
|
|
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"),
|
|
}
|
|
|
|
values := postgresURI.Query()
|
|
|
|
values.Add("sslmode", "disable")
|
|
|
|
databaseTz := viper.GetString("database.tz")
|
|
|
|
if len(databaseTz) == 0 {
|
|
localTz, _ := time.Now().Zone()
|
|
values.Add("timezone", localTz)
|
|
}
|
|
|
|
values.Add("timezone", viper.GetString("database.tz"))
|
|
|
|
postgresURI.RawQuery = values.Encode()
|
|
|
|
return postgresURI.String()
|
|
}
|