Use command line parameters

This commit is contained in:
Sonja Happ 2019-04-24 11:53:08 +02:00
parent 6ff38ffcfc
commit ec28a721f4
2 changed files with 21 additions and 7 deletions

View file

@ -65,7 +65,7 @@ test:backend:
script:
- go mod tidy
- cd common
- go test
- go test -v -args -dbhost=/var/lib/postgresql
dependencies:
- build:backend

View file

@ -5,14 +5,28 @@ import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres"
"log"
"flag"
)
const (
DB_NAME = "villasdb"
DB_DUMMY = "testvillasdb"
DB_HOST = "/tmp"
DB_SSLMODE = "disable" // TODO: change that for production
)
var DB_HOST string
var DB_NAME string
var DB_DUMMY string
var DB_SSLMODE string
// Initialize input command line flags
func init() {
flag.StringVar(&DB_HOST, "dbhost", "/tmp", "Host of the PostgreSQL database (default is /tmp)")
flag.StringVar(&DB_NAME, "dbname", "villasdb", "Name of the database to use (default is villasdb)")
flag.StringVar(&DB_DUMMY, "dbdummy", "testvillasdb", "Name of the test database to use (default is testvillasdb)")
flag.StringVar(&DB_SSLMODE, "dbsslmode", "disable", "SSL mode of DB (default is disable)") // TODO: change default for production
flag.Parse()
fmt.Println("DB_HOST has value ", DB_HOST)
fmt.Println("DB_NAME has value ", DB_NAME)
fmt.Println("DB_DUMMY has value ", DB_DUMMY)
fmt.Println("DB_SSLMODE has value ", DB_SSLMODE)
}
// Initialize connection to the database
func InitDB() *gorm.DB {