-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinterface.go
59 lines (50 loc) · 1.3 KB
/
interface.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
package ncserial
import (
"strings"
)
// Directive nginx config directive
type Directive interface {
Name() string
Value() interface{}
String() string
Parent() interface{}
SetParent(parent interface{})
SetIndentLevel(level int)
GetIndentLevel() int
}
// Directives slice of directive
// usage:
// sort.Sort(Directives(sliceOfDirective))
type Directives []Directive
// Len implements sort.Interface
func (d Directives) Len() int { return len(d) }
// Less implments sort.Interface
func (d Directives) Less(i, j int) bool {
siLower := strings.ToLower(d[i].Name())
sjLower := strings.ToLower(d[j].Name())
if siLower == sjLower {
return d[i].Name() < d[j].Name()
}
return siLower < sjLower
}
// Swap implements sort.Interface
func (d Directives) Swap(i, j int) {
d[i], d[j] = d[j], d[i]
}
//BlockDirective nginx block type directive with braces
type BlockDirective interface {
Directive
AddDirective(d Directive)
AddInterface(i interface{})
FindDirectiveByName(name string) (Directive, error)
}
// Marshaler is the interface implemented by types that
// can marshal themselves into valid Directive.
type Marshaler interface {
MarshalD() ([]Directive, error)
}
// Unmarshaler is the interface implemented by types
// that can unmarshal a Nginx directive
type Unmarshaler interface {
UnmarshalD([]byte) error
}