Why the hell...

This commit is contained in:
Daniel 2023-03-04 13:34:28 -05:00
parent 060650a7aa
commit 64f7831fe1
4 changed files with 20 additions and 6 deletions

View file

@ -21,6 +21,7 @@ var (
DB_URL = "" DB_URL = ""
DB_USER = "" DB_USER = ""
DB_PASSWORD = "" DB_PASSWORD = ""
DB_NAME = ""
) )
func init() { func init() {
@ -36,6 +37,10 @@ func init() {
DB_PASSWORD = strings.TrimSpace(dbPassword) DB_PASSWORD = strings.TrimSpace(dbPassword)
} }
if dbName, ok := os.LookupEnv("DB_NAME"); ok {
DB_NAME = strings.TrimSpace(dbName)
}
if len(os.Args) != 2 { if len(os.Args) != 2 {
log.Fatalf("Usage: %s <init|up|down|status|mark_applied>", os.Args[0]) log.Fatalf("Usage: %s <init|up|down|status|mark_applied>", os.Args[0])
} }
@ -48,7 +53,7 @@ func main() {
pgdriver.WithTLSConfig(&tls.Config{InsecureSkipVerify: true}), pgdriver.WithTLSConfig(&tls.Config{InsecureSkipVerify: true}),
pgdriver.WithUser(DB_USER), pgdriver.WithUser(DB_USER),
pgdriver.WithPassword(DB_PASSWORD), pgdriver.WithPassword(DB_PASSWORD),
pgdriver.WithDatabase("postgres"), pgdriver.WithDatabase(DB_NAME),
pgdriver.WithInsecure(true), pgdriver.WithInsecure(true),
pgdriver.WithTimeout(5*time.Second), pgdriver.WithTimeout(5*time.Second),
pgdriver.WithDialTimeout(5*time.Second), pgdriver.WithDialTimeout(5*time.Second),

1
env/example.dev.env vendored
View file

@ -3,4 +3,5 @@ export POSTGRES_PASSWORD=password
export DB_URL="$(hostname):5432" export DB_URL="$(hostname):5432"
export DB_USER=${POSTGRES_USER} export DB_USER=${POSTGRES_USER}
export DB_PASSWORD=${POSTGRES_PASSWORD} export DB_PASSWORD=${POSTGRES_PASSWORD}
export DB_NAME=oscar
export OSCAR_BOS_HOST=$(osascript -e "IPv4 address of (system info)") export OSCAR_BOS_HOST=$(osascript -e "IPv4 address of (system info)")

11
main.go
View file

@ -36,6 +36,7 @@ var (
DB_URL = "" DB_URL = ""
DB_USER = "" DB_USER = ""
DB_PASSWORD = "" DB_PASSWORD = ""
DB_NAME = ""
) )
func init() { func init() {
@ -75,6 +76,10 @@ func init() {
DB_PASSWORD = strings.TrimSpace(dbPassword) DB_PASSWORD = strings.TrimSpace(dbPassword)
} }
if dbName, ok := os.LookupEnv("DB_NAME"); ok {
DB_NAME = strings.TrimSpace(dbName)
}
flag.Parse() flag.Parse()
OSCAR_HOST = oscarHost OSCAR_HOST = oscarHost
@ -96,6 +101,10 @@ func init() {
if DB_PASSWORD == "" { if DB_PASSWORD == "" {
log.Fatalln("DB password not specified") log.Fatalln("DB password not specified")
} }
if DB_NAME == "" {
log.Fatalln("DB name not specified")
}
} }
func main() { func main() {
@ -105,7 +114,7 @@ func main() {
pgdriver.WithTLSConfig(&tls.Config{InsecureSkipVerify: true}), pgdriver.WithTLSConfig(&tls.Config{InsecureSkipVerify: true}),
pgdriver.WithUser(DB_USER), pgdriver.WithUser(DB_USER),
pgdriver.WithPassword(DB_PASSWORD), pgdriver.WithPassword(DB_PASSWORD),
pgdriver.WithDatabase("postgres"), pgdriver.WithDatabase(DB_NAME),
pgdriver.WithInsecure(true), pgdriver.WithInsecure(true),
pgdriver.WithTimeout(5*time.Second), pgdriver.WithTimeout(5*time.Second),
pgdriver.WithDialTimeout(5*time.Second), pgdriver.WithDialTimeout(5*time.Second),

7
run.sh
View file

@ -1,5 +1,4 @@
#!/bin/bash #!/bin/sh
source env/dev.env . dev.env
npm install ./aim-oscar
npm run dev