-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathMain.go
56 lines (43 loc) · 867 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
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"./gomet"
"fmt"
"log"
"math/rand"
"os"
"sync"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
err := os.MkdirAll("logs", 0700)
if err != nil {
fmt.Printf("Failed to create logs directory %s\n", err)
return
}
err = os.MkdirAll("share", 0700)
if err != nil {
fmt.Printf("Failed to create share directory %s\n", err)
return
}
logFile, _ := os.Create("logs/client.log")
log.SetOutput(logFile)
config, err := gomet.LoadConfig()
if err != nil {
fmt.Printf("Invalid configuration file: %s\n", err)
return
}
var wg sync.WaitGroup
wg.Add(1)
server := gomet.NewServer(&wg, config)
server.Start()
cli := gomet.NewCLI(server)
go cli.Start()
if config.Api.Enable {
api := gomet.NewApi(server)
go api.Start()
}
log.Printf("Waiting for server to stop")
wg.Wait()
log.Printf("Server stopped")
}