-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (50 loc) · 1.46 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"log"
"os"
sj "github.com/OIT-ADS-Web/scramjet"
"github.com/namsral/flag"
)
// make this a server?
func main() {
var conf sj.Config
dbServer := flag.String("DB_SERVER", "", "database server")
dbPort := flag.Int("DB_PORT", 0, "database port")
dbDatabase := flag.String("DB_DATABASE", "", "database database")
dbUser := flag.String("DB_USER", "", "database user")
dbPassword := flag.String("DB_PASSWORD", "", "database password")
dbMaxConnections := flag.Int("DB_MAX_CONNECTIONS", 1, "database maximum pool conections")
dbAquireTimeout := flag.Int("DB_ACQUIRE_TIMEOUT", 30, "how many seconds to wait to get connection")
flag.Parse()
if len(*dbServer) == 0 && len(*dbUser) == 0 {
log.Fatal("database credentials need to be set")
} else {
database := sj.DatabaseInfo{
Server: *dbServer,
Database: *dbDatabase,
Password: *dbPassword,
Port: *dbPort,
User: *dbUser,
MaxConnections: *dbMaxConnections,
AcquireTimeout: *dbAquireTimeout,
Application: "scramjet",
}
conf = sj.Config{
Database: database,
}
}
if err := sj.MakeConnectionPool(conf); err != nil {
fmt.Printf("could not establish postgresql connection %s\n", err)
os.Exit(1)
}
if !sj.StagingTableExists() {
fmt.Println("staging table not found")
sj.MakeStagingSchema()
}
if !sj.ResourceTableExists() {
fmt.Println("resources table not found")
sj.MakeResourceSchema()
}
defer sj.DBPool.Close()
}