diff --git a/internal/cnf/nginx.go b/internal/cnf/nginx.go index a2e2581..bdf6f2c 100644 --- a/internal/cnf/nginx.go +++ b/internal/cnf/nginx.go @@ -38,7 +38,7 @@ func (d *nginx) WriteTo(_writer io.Writer) (int64, error) { // if 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, ""}, diff --git a/internal/cnf/parser/nginx/decoder.go b/internal/cnf/parser/nginx/decoder.go index 4af5ac4..2cc8f79 100644 --- a/internal/cnf/parser/nginx/decoder.go +++ b/internal/cnf/parser/nginx/decoder.go @@ -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 { diff --git a/internal/cnf/parser/nginx/encoder.go b/internal/cnf/parser/nginx/encoder.go index 567e1a9..104d51f 100644 --- a/internal/cnf/parser/nginx/encoder.go +++ b/internal/cnf/parser/nginx/encoder.go @@ -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 that begins each line (default is emptys string) +// and the 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 { diff --git a/internal/cnf/parser/nginx/nginx.go b/internal/cnf/parser/nginx/nginx.go index 9ac9b87..cec8618 100644 --- a/internal/cnf/parser/nginx/nginx.go +++ b/internal/cnf/parser/nginx/nginx.go @@ -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} }