Documentation
¶
Index ¶
- func Write(f File, output string) error
- type Comment
- type Field
- type File
- func AppendBlankLineToFile(f File) File
- func AppendBlankLineToSection(f File, sectionName, subsectionName string) (File, bool)
- func AppendFieldToSection(f File, fieldName, fieldValue, sectionName, subsectionName string) File
- func DeleteAllFieldsWithName(f File, fieldName, sectionName, subsectionName string) File
- func DeleteFieldWithValue(f File, fieldName, fieldValue, sectionName, subsectionName string) File
- func DeleteSection(file File, sect, subsection string) File
- func InjectField(f File, fieldName, fieldValue, sectionName, subsectionName string, ...) File
- func MakeNewSection(f File, sectionName, subsectionName string) (File, bool)
- func MergeAllDuplicateSections(file File) File
- func Read(file io.Reader) File
- type Section
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Comment ¶
type Comment struct {
Str string
}
Comment is any whitespace or comment that is ignored by this parser
type Field ¶
type Field struct { Str string // The literal value of this line, including comments and whitespace e.g. Foo = Bar ; test Name string Value string TrailingComment string // Any comments or whitespace after the field value CommentsBefore []*Comment // Any comments or whitespace between this field and whatever came before }
type File ¶
type File struct { Sections []*Section CommentsAfter []*Comment // Any comments or whitespace that come at the end of a file Fields []*Field // Fields that don't belong to a section }
File is an AST representation of a config file
func AppendBlankLineToFile ¶
AppendBlankLine appends an empty line to the file.
func AppendBlankLineToSection ¶
AppendBlankLineToSection appends an empty to a section
func AppendFieldToSection ¶
AppendFieldToSection appends a field to a section with no knowledge of whether the field is repeatable or not. Creates a new section if section does not exist
func DeleteAllFieldsWithName ¶
DeleteAllFieldsWithName deletes all fields with the name fieldName in section [sectionName "subsectionName"]
func DeleteFieldWithValue ¶
DeleteFieldWithValue deletes a field from a section if the name and value are fieldName and fieldValue
func DeleteSection ¶
DeleteSection deletes all sections found in the AST with the name sect
func InjectField ¶
func InjectField(f File, fieldName, fieldValue, sectionName, subsectionName string, repeatable bool) File
InjectField injects a field into the AST and returns the modified file. If multiple sections exist with the same name, the field is inserted into the first one found.
func MakeNewSection ¶
MakeNewSection writes a new section heading to the file. Returns !ok if section already exists.
func MergeAllDuplicateSections ¶
MergeAllDuplicateSections merges all sections with duplicate names, along with any fields and comments belonging to them
func (File) MaybeGetSection ¶
MaybeGetSection returns a pointer to a section with name sectionName and subsection subsectionName. Returns nil if section does not exist.