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

56 lines
1.2 KiB
Go

package nginx
// LineType enumerates available line types
type LineType byte
const (
// NONE is the default line type (invalid syntax)
NONE LineType = iota
// COMMENT represents a #-comment
COMMENT
// COLONCOMMENT represents a ;-comment
COLONCOMMENT
// ASSIGNMENT line
ASSIGNMENT
// INCLUDE line
INCLUDE
// SECTION start
SECTION
// SECTIONEND line '}'
SECTIONEND
)
// Line represents a meaningful line
type Line struct {
// Type of line
Type LineType
// Components of the line
Components []string
// Lines children of the current section (nil if not a section)
Lines []*Line
}
// Section returns the section with a given name *directly*
// inside the current line ; nil is returned if no match found
func (l *Line) 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
// *directly* inside the current line ; nil is returned if no match found
func (l *Line) Get(name string) *Line {
for _, elem := range l.Lines {
if elem.Type == ASSIGNMENT && elem.Components[0] == name {
return elem
}
}
return nil
}