/
server.go
52 lines (42 loc) · 943 Bytes
/
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
package main
import (
"github.com/zubairhamed/gossamer/store"
"github.com/zubairhamed/gossamer/webapp/server"
"gopkg.in/yaml.v2"
"io/ioutil"
"path/filepath"
)
func main() {
cfg, err := parseConfig()
if err != nil {
panic(err)
}
s := server.NewServer(cfg.Host, cfg.Port)
s.UseStore(store.NewMongoStore(cfg.MongoDatabase.Host, cfg.MongoDatabase.Database))
s.Start()
}
func parseConfig() (*AppConfig, error) {
cfgPath, err := filepath.Abs("./config.yml")
if err != nil {
return nil, err
}
buf, err := ioutil.ReadFile(cfgPath)
if err != nil {
return nil, err
}
var cfg *AppConfig = &AppConfig{}
err = yaml.Unmarshal(buf, &cfg)
if err != nil {
return nil, err
}
return cfg, nil
}
type AppConfig struct {
Name string `yaml:"name"`
Host string `yaml:"host"`
Port int `yaml:"port"`
MongoDatabase struct {
Host string `yaml:"host"`
Database string `yaml:"database"`
} `yaml:"datasource-mongo"`
}