2018-11-12 07:41:00 +00:00
|
|
|
package nginx
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
)
|
|
|
|
|
|
|
|
type nginx struct {
|
|
|
|
Lines []*Line
|
|
|
|
}
|
|
|
|
|
2018-11-12 11:08:54 +00:00
|
|
|
// NewDecoder implements parser.T
|
2018-11-12 07:41:00 +00:00
|
|
|
func (n *nginx) NewDecoder(r io.Reader) *decoder {
|
|
|
|
return &decoder{reader: r}
|
|
|
|
}
|
2018-11-12 14:35:45 +00:00
|
|
|
|
|
|
|
// Section returns the section with a given name at the root level
|
|
|
|
// nil is returned if no match found
|
|
|
|
func (l *nginx) Section(name string) *Line {
|
|
|
|
for _, elem := range l.Lines {
|
|
|
|
if elem.Type == SECTION && elem.Components[0] == name {
|
|
|
|
return elem
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get returns a pointer to the assignment line the given name as key
|
|
|
|
// at the root level
|
|
|
|
func (l *nginx) Get(name string) *Line {
|
|
|
|
for _, elem := range l.Lines {
|
|
|
|
if elem.Type == ASSIGNMENT && elem.Components[0] == name {
|
|
|
|
return elem
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|