nix-amer/internal/cnf/parser/nginx/nginx.go

42 lines
818 B
Go

package nginx
import (
"io"
)
type nginx struct {
Lines []*Line
}
// NewDecoder implements parser.T
func NewDecoder(r io.Reader) *decoder {
return &decoder{reader: r}
}
// NewEncoder implements parser.T
func NewEncoder(w io.Writer) *encoder {
return &encoder{writer: w}
}
// 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
}