forked from ortuman/jackal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
61 lines (52 loc) · 1.53 KB
/
config.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
58
59
60
61
/*
* Copyright (c) 2018 Miguel Ángel Ortuño.
* See the LICENSE file for more information.
*/
package app
import (
"bytes"
"io/ioutil"
"github.com/ortuman/jackal/cluster"
"github.com/ortuman/jackal/c2s"
"github.com/ortuman/jackal/component"
"github.com/ortuman/jackal/module"
"github.com/ortuman/jackal/router"
"github.com/ortuman/jackal/s2s"
"github.com/ortuman/jackal/storage"
yaml "gopkg.in/yaml.v2"
)
// debugConfig represents debug server configuration.
type debugConfig struct {
Port int `yaml:"port"`
}
type loggerConfig struct {
Level string `yaml:"level"`
LogPath string `yaml:"log_path"`
}
// Config represents a global configuration.
type Config struct {
PIDFile string `yaml:"pid_path"`
Debug debugConfig `yaml:"debug"`
Logger loggerConfig `yaml:"logger"`
Storage storage.Config `yaml:"storage"`
Cluster *cluster.Config `yaml:"cluster"`
Router router.Config `yaml:"router"`
Modules module.Config `yaml:"modules"`
Components component.Config `yaml:"components"`
C2S []c2s.Config `yaml:"c2s"`
S2S *s2s.Config `yaml:"s2s"`
}
// FromFile loads default global configuration from
// a specified file.
func (cfg *Config) FromFile(configFile string) error {
b, err := ioutil.ReadFile(configFile)
if err != nil {
return err
}
return yaml.Unmarshal(b, cfg)
}
// FromBuffer loads default global configuration from
// a specified byte buffer.
func (cfg *Config) FromBuffer(buf *bytes.Buffer) error {
return yaml.Unmarshal(buf.Bytes(), cfg)
}