-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (41 loc) · 932 Bytes
/
Copy pathmain.go
File metadata and controls
50 lines (41 loc) · 932 Bytes
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 (
"encoding/json"
"flag"
"github.com/c16a/microq/broker"
"github.com/c16a/microq/config"
"github.com/c16a/microq/interfaces"
"github.com/c16a/microq/storage"
"log"
"os"
)
var configFileName string
func init() {
flag.StringVar(&configFileName, "config", "config.json", "configuration file")
}
func main() {
flag.Parse()
c, err := ParseJsonFile[config.Config](configFileName)
if err != nil {
panic(err)
}
b := broker.NewBroker()
var storageProvider = storage.NewFileStorageProvider(c)
defer storageProvider.Close()
go interfaces.RunWs(b, storageProvider)
log.Fatal(interfaces.RunTcp(b, storageProvider))
}
func ParseJsonFile[T any](path string) (*T, error) {
var config T
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
decoder := json.NewDecoder(file)
err = decoder.Decode(&config)
if err != nil {
return nil, err
}
return &config, nil
}