Skip to content

Commit

Permalink
add database url to config file
Browse files Browse the repository at this point in the history
  • Loading branch information
zu1k committed Sep 5, 2020
1 parent 5ef4144 commit 65ad07f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
3 changes: 3 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# your domain
domain: example.com

# database url
database_url: ""

# cloudflare api
cf_email: ""
cf_key: ""
Expand Down
5 changes: 5 additions & 0 deletions internal/database/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"os"

"github.com/zu1k/proxypool/config"

"gorm.io/driver/postgres"
"gorm.io/gorm"
)
Expand All @@ -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
}
Expand Down

0 comments on commit 65ad07f

Please sign in to comment.