-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
50 lines (42 loc) · 968 Bytes
/
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
package main
import (
"fmt"
"io/ioutil"
"github.com/domdom82/go-responder/http"
"github.com/domdom82/go-responder/tcp"
"github.com/domdom82/go-responder/websocket"
"gopkg.in/yaml.v2"
)
type ServerConfig struct {
Http *http.Config `yaml:"http"`
Tcp *tcp.Config `yaml:"tcp"`
Websocket *websocket.Config `yaml:"websocket"`
}
type Config struct {
ServerConfigs []*ServerConfig `yaml:"servers"`
}
func NewServerConfigFromFile(filename string) (*Config, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
var config *Config
err = yaml.Unmarshal(data, &config)
if err != nil {
return nil, err
}
return config, nil
}
func (cfg ServerConfig) String() string {
s := ""
if cfg.Http != nil {
s = fmt.Sprintf("{http: %v}", cfg.Http)
}
if cfg.Tcp != nil {
s = fmt.Sprintf("{tcp: %v}", cfg.Tcp)
}
if cfg.Websocket != nil {
s = fmt.Sprintf("{websocket: %v}", cfg.Websocket)
}
return s
}