-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.go
43 lines (33 loc) · 860 Bytes
/
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
package main
import (
"database/sql"
"log"
"net/http"
"os"
_ "github.com/joho/godotenv/autoload"
)
var sphinx *sql.DB
var mysql *sql.DB
var hostname string
func main() {
hostname := getEnv("HOSTNAME", "example.com")
amqpHost := getEnv("AMQP_HOST", "")
sphinxDatabase := getEnv("SEARCH_DATABASE", "tcp(127.0.0.1:9306)/?interpolateParams=true")
nukesDatabase := getEnv("NUKES_DATABASE", "")
listenAddr := getEnv("LISTEN_ADDRESS", "127.0.0.1:8088")
sphinx = newMysql(sphinxDatabase)
mysql = newMysql(nukesDatabase)
router := newRouter(hostname)
newMQ(amqpHost)
log.Fatal(http.ListenAndServe(listenAddr, router))
}
func getEnv(key, defaultValue string) string {
value, exists := os.LookupEnv(key)
if !exists {
if defaultValue == "" {
log.Fatal("Missing mandatory env variable : " + key)
}
return defaultValue
}
return value
}