forked from cyverse-de/user-info
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
87 lines (68 loc) · 1.91 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
_ "expvar"
"flag"
"net/http"
"os"
"github.com/cyverse-de/configurate"
"github.com/cyverse-de/dbutil"
_ "github.com/lib/pq"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
// IplantSuffix is what is appended to a username in the database.
const IplantSuffix = "@iplantcollaborative.org"
func main() {
var (
showVersion = flag.Bool("version", false, "Print the version information")
cfgPath = flag.String("config", "/etc/iplant/de/jobservices.yml", "The path to the config file")
port = flag.String("port", "60000", "The port number to listen on")
err error
cfg *viper.Viper
)
flag.Parse()
if *showVersion {
AppVersion()
os.Exit(0)
}
if *cfgPath == "" {
log.Fatal("--config must be set")
}
if cfg, err = configurate.InitDefaults(*cfgPath, configurate.JobServicesDefaults); err != nil {
log.Fatal(err.Error())
}
dburi := cfg.GetString("db.uri")
connector, err := dbutil.NewDefaultConnector("1m")
if err != nil {
log.Fatal(err.Error())
}
log.Info("Connecting to the database...")
db, err := connector.Connect("postgres", dburi)
if err != nil {
log.Fatal(err.Error())
}
defer db.Close()
log.Info("Connected to the database.")
if err := db.Ping(); err != nil {
log.Fatal(err.Error())
}
log.Info("Successfully pinged the database")
userDomain := cfg.GetString("users.domain")
if userDomain == "" {
userDomain = IplantSuffix
}
router := makeRouter()
prefsDB := NewPrefsDB(db)
prefsApp := NewPrefsApp(prefsDB, router)
sessionsDB := NewSessionsDB(db)
sessionsApp := NewSessionsApp(sessionsDB, router)
searchesDB := NewSearchesDB(db)
searchesApp := NewSearchesApp(searchesDB, router)
bagsApp := NewBagsApp(db, router, userDomain)
log.Debug(prefsApp)
log.Debug(sessionsApp)
log.Debug(searchesApp)
log.Debug(bagsApp)
log.Info("Listening on port ", *port)
log.Fatal(http.ListenAndServe(fixAddr(*port), router))
}