forked from tufanbarisyildirim/gonginx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
55 lines (51 loc) · 1.49 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
package gonginx
//Config represents a whole config file.
type Config struct {
*Block
FilePath string
}
//TODO(tufan): move that part inti dumper package
//SaveToFile save config to a file
//TODO: add custom file / folder path support
//func (c *Config) SaveToFile(style *dumper.Style) error {
// //wrilte file
// dirPath := filepath.Dir(c.FilePath)
// if _, err := os.Stat(dirPath); err != nil {
// err := os.MkdirAll(dirPath, os.ModePerm)
// if err != nil {
// return err //TODO: do we reallt need to find a way to test dir creating error?
// }
// }
//
// //write main file
// err := ioutil.WriteFile(c.FilePath, c.ToByteArray(style), 0644)
// if err != nil {
// return err //TODO: do we need to find a way to test writing error?
// }
//
// //write sub files (inlude /file/path)
// for _, directive := range c.Block.Directives {
// if fs, ok := (interface{}(directive)).(FileDirective); ok {
// err := fs.SaveToFile(style)
// if err != nil {
// return err
// }
// }
// }
//
// return nil
//}
//FindDirectives find directives from whole config block
func (c *Config) FindDirectives(directiveName string) []IDirective {
return c.Block.FindDirectives(directiveName)
}
//FindUpstreams find directives from whole config block
func (c *Config) FindUpstreams() []*Upstream {
var upstreams []*Upstream
directives := c.Block.FindDirectives("upstream")
for _, directive := range directives {
// up, _ := NewUpstream(directive)
upstreams = append(upstreams, directive.(*Upstream))
}
return upstreams
}