This commit is contained in:
xdrm-brackets 2018-11-12 19:45:30 +01:00
parent d88b053dc5
commit aa3c8e472d
4 changed files with 19 additions and 15 deletions

View File

@ -38,7 +38,7 @@ func (d *nginx) WriteTo(_writer io.Writer) (int64, error) {
// if <create> is true, create if does not exist
func (d *nginx) browse(_path string, create ...bool) (*lib.Line, bool) {
must_create := len(create) > 0 && create[0]
mustCreate := len(create) > 0 && create[0]
// 1. extract path
path := strings.Split(_path, ".")
@ -49,7 +49,7 @@ func (d *nginx) browse(_path string, create ...bool) (*lib.Line, bool) {
}
// 3. init output chain
var current *lib.Line = d.data
current := d.data
// 4. iterate over path / nested fields
l := len(path)
@ -71,7 +71,7 @@ func (d *nginx) browse(_path string, create ...bool) (*lib.Line, bool) {
}
// create section
if must_create {
if mustCreate {
sec := &lib.Line{
Type: lib.SECTION,
Components: []string{field},
@ -93,7 +93,7 @@ func (d *nginx) browse(_path string, create ...bool) (*lib.Line, bool) {
}
// create assignment
if must_create {
if mustCreate {
assignment := &lib.Line{
Type: lib.ASSIGNMENT,
Components: []string{field, ""},

View File

@ -7,10 +7,11 @@ import (
"strings"
)
// decoder implements parser.Decoder
type decoder struct{ reader io.Reader }
// Decoder implements parser.Decoder
type Decoder struct{ reader io.Reader }
func (d *decoder) Decode(v interface{}) error {
// Decode is the main function of the parser.Decoder interface
func (d *Decoder) Decode(v interface{}) error {
// check 'v'
if v == nil {

View File

@ -10,14 +10,16 @@ var (
defaultIndent = "\t"
)
// encoder implements parser.Encoder
type encoder struct {
// Encoder implements parser.Encoder
type Encoder struct {
writer io.Writer
prefix []byte
indent []byte
}
func (e *encoder) SetIndent(prefix, indent string) {
// SetIndent with the <prefix> that begins each line (default is emptys string)
// and the <indent> string repeated for each indentation level (default is tab '\t')
func (e *Encoder) SetIndent(prefix, indent string) {
e.prefix = make([]byte, 0)
e.prefix = append(e.prefix, []byte(prefix)...)
@ -25,7 +27,8 @@ func (e *encoder) SetIndent(prefix, indent string) {
e.indent = append(e.indent, []byte(indent)...)
}
func (e *encoder) Encode(v interface{}) error {
// Encode is the main function of the parser.Encoder interface
func (e *Encoder) Encode(v interface{}) error {
// default indentation
if e.prefix == nil || e.indent == nil {

View File

@ -5,11 +5,11 @@ import (
)
// NewDecoder implements parser.T
func NewDecoder(r io.Reader) *decoder {
return &decoder{reader: r}
func NewDecoder(r io.Reader) *Decoder {
return &Decoder{reader: r}
}
// NewEncoder implements parser.T
func NewEncoder(w io.Writer) *encoder {
return &encoder{writer: w}
func NewEncoder(w io.Writer) *Encoder {
return &Encoder{writer: w}
}