add database url to config file

This commit is contained in:
zu1k
2020-09-05 12:03:22 +08:00
parent 5ef4144e72
commit 65ad07f579
3 changed files with 9 additions and 0 deletions

View File

@@ -14,6 +14,7 @@ var configFilePath = "config.yaml"
type ConfigOptions struct {
Domain string `json:"domain" yaml:"domain"`
DatabaseUrl string `json:"database_url" yaml:"database_url"`
CFEmail string `json:"cf_email" yaml:"cf_email"`
CFKey string `json:"cf_key" yaml:"cf_key"`
SourceFiles []string `json:"source-files" yaml:"source-files"`

View File

@@ -1,6 +1,9 @@
# your domain
domain: example.com
# database url
database_url: ""
# cloudflare api
cf_email: ""
cf_key: ""

View File

@@ -4,6 +4,8 @@ import (
"fmt"
"os"
"github.com/zu1k/proxypool/config"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
@@ -12,6 +14,9 @@ var DB *gorm.DB
func connect() (err error) {
dsn := "user=proxypool password=proxypool dbname=proxypool port=5432 sslmode=disable TimeZone=Asia/Shanghai"
if url := config.Config.DatabaseUrl; url != "" {
dsn = url
}
if url := os.Getenv("DATABASE_URL"); url != "" {
dsn = url
}