-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
45 lines (37 loc) · 951 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
44
45
package main
import (
"5pmGebetServer/web"
"log"
"net/http"
"os"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "8080"
log.Printf("using default port: %s", port)
}
dbPath := os.Getenv("DB_PATH")
if dbPath == "" {
dbPath = "./pray.db"
log.Printf("using default db path: %s", dbPath)
}
masterkey := os.Getenv("MASTERKEY")
if masterkey == "" {
log.Println("no new master key specified")
}
db := openDatabase(dbPath, masterkey)
defer db.Close()
web.SetDatabase(db)
directory := os.Getenv("DIRECTORY")
if directory == "" {
log.Println("using default directory \"web/static/\"")
directory = "web/static/"
}
http.HandleFunc("/api", web.ApiHandle)
http.HandleFunc("/api/view", web.ApiView)
http.HandleFunc("/api/key", web.ApiKey)
http.Handle("/", http.FileServer(http.Dir(directory)))
log.Printf("Serving %s on HTTP port: %s\n", directory, port)
log.Fatal(http.ListenAndServe(":"+port, nil))
}