Skip to content

Commit fa635d3

Browse files
AndresCidoncharaphink
authored andcommitted
feat: Database port should be configurable
Avoid dependencies and executable in git Add vendor/ and terraboard to .gitignore
1 parent d79bc2d commit fa635d3

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
hugo/public
2+
vendor/
3+
terraboard

config/config.go

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type Config struct {
2626

2727
DB struct {
2828
Host string `long:"db-host" env:"DB_HOST" yaml:"host" description:"Database host." default:"db"`
29+
Port string `long:"db-port" env:"DB_PORT" yaml:"port" description:"Database port." default:"5432"`
2930
User string `long:"db-user" env:"DB_USER" yaml:"user" description:"Database user." default:"gorm"`
3031
Password string `long:"db-password" env:"DB_PASSWORD" yaml:"password" description:"Database password."`
3132
Name string `long:"db-name" env:"DB_NAME" yaml:"name" description:"Database name." default:"gorm"`

db/db.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ type Database struct {
2626
var pageSize = 20
2727

2828
// Init setups up the Database and a pointer to it
29-
func Init(host, user, dbname, password, logLevel string) *Database {
29+
func Init(host, port, user, dbname, password, logLevel string) *Database {
3030
var err error
31-
connString := fmt.Sprintf("host=%s user=%s dbname=%s sslmode=disable password=%s", host, user, dbname, password)
31+
connString := fmt.Sprintf("host=%s port=%s user=%s dbname=%s sslmode=disable password=%s", host, port, user, dbname, password)
3232
db, err := gorm.Open("postgres", connString)
3333
if err != nil {
3434
log.Fatal(err)

main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,9 @@ func main() {
146146

147147
// Set up the DB and start S3->DB sync
148148
database := db.Init(
149-
c.DB.Host, c.DB.User,
150-
c.DB.Name, c.DB.Password,
151-
c.Log.Level)
149+
c.DB.Host, c.DB.Port,
150+
c.DB.User, c.DB.Password,
151+
c.DB.Name, c.Log.Level)
152152
if c.DB.NoSync {
153153
log.Infof("Not syncing database, as requested.")
154154
} else {

0 commit comments

Comments
 (0)