-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
49 lines (39 loc) · 1.08 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
package main
import (
"fmt"
"log"
"math/rand"
"net/http"
"time"
"github.com/fatih/color"
"github.com/gorilla/handlers"
)
const keysDir = "keys"
const keysize = 2048
const hashize = 1536
func main() {
color.Blue("Starting darkID-libarary-login-example")
readConfig("config.json")
fmt.Println(config)
//initialize rand
rand.Seed(time.Now().UnixNano())
//initialize token
initializeToken()
//run thw webserver
go GUI()
//run API
log.Println("api server running")
log.Print("port: ")
log.Println(config.Port)
router := NewRouter()
headersOk := handlers.AllowedHeaders([]string{"X-Requested-With", "Access-Control-Allow-Origin"})
originsOk := handlers.AllowedOrigins([]string{"*"})
methodsOk := handlers.AllowedMethods([]string{"GET", "HEAD", "POST", "PUT", "OPTIONS"})
log.Fatal(http.ListenAndServe(":"+config.Port, handlers.CORS(originsOk, headersOk, methodsOk)(router)))
}
func GUI() {
//here, run webserver
log.Println("webserver in port " + config.WebServerPort)
http.Handle("/", http.FileServer(http.Dir("./web")))
http.ListenAndServe(":"+config.WebServerPort, nil)
}