forked from ortuman/jackal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
58 lines (50 loc) · 1.41 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
/*
* Copyright (c) 2018 Miguel Ángel Ortuño.
* See the LICENSE file for more information.
*/
package main
import (
"bytes"
"io/ioutil"
"github.com/ortuman/jackal/c2s"
"github.com/ortuman/jackal/host"
"github.com/ortuman/jackal/log"
"github.com/ortuman/jackal/module"
"github.com/ortuman/jackal/s2s"
"github.com/ortuman/jackal/storage"
"gopkg.in/yaml.v2"
)
// DebugConfig represents debug server configuration.
type DebugConfig struct {
Port int `yaml:"port"`
}
// TLSConfig represents a server TLS configuration.
type TLSConfig struct {
CertFile string `yaml:"cert_path"`
PrivKeyFile string `yaml:"privkey_path"`
}
// Config represents a global configuration.
type Config struct {
PIDFile string `yaml:"pid_path"`
Debug DebugConfig `yaml:"debug"`
Logger log.Config `yaml:"logger"`
Storage storage.Config `yaml:"storage"`
Hosts []host.Config `yaml:"hosts"`
Modules module.Config `yaml:"modules"`
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)
}