-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
50 lines (44 loc) · 1.12 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
package main
import (
"fmt"
"io"
"log"
"net/http"
"os"
"runtime"
"time"
//"github.com/engineerbeard/barrenschat-api/handler"
"github.com/dbubel/barrenschat-api/hub"
"github.com/dbubel/barrenschat-api/middleware"
)
func PrintMemUsage() {
for {
var m runtime.MemStats
runtime.ReadMemStats(&m)
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
fmt.Printf("Alloc = %v MiB", bToMb(m.Alloc))
fmt.Printf("\tTotalAlloc = %v MiB", bToMb(m.TotalAlloc))
fmt.Printf("\tSys = %v MiB", bToMb(m.Sys))
fmt.Printf("\tNumGC = %v\n", m.NumGC)
time.Sleep(time.Second * 5)
}
}
func bToMb(b uint64) uint64 {
return b / 1024 / 1024
}
// TODO: benchcmp
func main() {
// f, err := os.OpenFile("hub_log.txt", os.O_APPEND|os.O_CREATE|os.O_RDWR, 0666)
// if err != nil {
// log.Fatal(err)
// }
// defer f.Close()
mw := io.MultiWriter(os.Stdout)
log.SetOutput(mw)
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
hubHandle := hub.NewHub()
go hubHandle.Run()
serverMux := hub.GetMux(hubHandle, middleware.AuthUser)
log.Println("Server running port 9000")
log.Fatalln(http.ListenAndServe(":9000", serverMux))
}