-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
57 lines (45 loc) · 1.1 KB
/
server.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
package main
import (
"encoding/json"
"log"
"net/http"
"./config"
"./login"
"./socket"
"github.com/boltdb/bolt"
)
var data login.UserList
func main() {
db, err := bolt.Open("users.db", 0600, nil)
if err != nil {
log.Fatal(err)
}
defer db.Close()
db.View(func(tx *bolt.Tx) error {
var user login.User
b := tx.Bucket([]byte("users"))
v := b.Get([]byte("ADMIN"))
err := json.Unmarshal(v, &user)
if err != nil {
return err
}
data.List = append(data.List, user)
return nil
})
log.SetFlags(log.Lshortfile)
conf := config.DecodeConfiguration()
apiKey := []byte(conf.SigningKey)
hub := socket.NewHub(conf.Mode, &data)
go hub.Run()
http.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) {
login.API(&data, w, r, apiKey, conf.Mode, db)
})
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
socket.ServeWs(&data, hub, w, r, apiKey)
})
http.Handle("/", http.FileServer(http.Dir("./client/")))
if conf.Mode == "Debug" {
log.Println("Blue Shift ---Online--- localhost", conf.Port)
}
log.Fatal(http.ListenAndServe(conf.Port, nil))
}