lint
This commit is contained in:
parent
d88b053dc5
commit
aa3c8e472d
|
@ -38,7 +38,7 @@ func (d *nginx) WriteTo(_writer io.Writer) (int64, error) {
|
||||||
// if <create> is true, create if does not exist
|
// if <create> is true, create if does not exist
|
||||||
func (d *nginx) browse(_path string, create ...bool) (*lib.Line, bool) {
|
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
|
// 1. extract path
|
||||||
path := strings.Split(_path, ".")
|
path := strings.Split(_path, ".")
|
||||||
|
@ -49,7 +49,7 @@ func (d *nginx) browse(_path string, create ...bool) (*lib.Line, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. init output chain
|
// 3. init output chain
|
||||||
var current *lib.Line = d.data
|
current := d.data
|
||||||
|
|
||||||
// 4. iterate over path / nested fields
|
// 4. iterate over path / nested fields
|
||||||
l := len(path)
|
l := len(path)
|
||||||
|
@ -71,7 +71,7 @@ func (d *nginx) browse(_path string, create ...bool) (*lib.Line, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create section
|
// create section
|
||||||
if must_create {
|
if mustCreate {
|
||||||
sec := &lib.Line{
|
sec := &lib.Line{
|
||||||
Type: lib.SECTION,
|
Type: lib.SECTION,
|
||||||
Components: []string{field},
|
Components: []string{field},
|
||||||
|
@ -93,7 +93,7 @@ func (d *nginx) browse(_path string, create ...bool) (*lib.Line, bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create assignment
|
// create assignment
|
||||||
if must_create {
|
if mustCreate {
|
||||||
assignment := &lib.Line{
|
assignment := &lib.Line{
|
||||||
Type: lib.ASSIGNMENT,
|
Type: lib.ASSIGNMENT,
|
||||||
Components: []string{field, ""},
|
Components: []string{field, ""},
|
||||||
|
|
|
@ -7,10 +7,11 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// decoder implements parser.Decoder
|
// Decoder implements parser.Decoder
|
||||||
type decoder struct{ reader io.Reader }
|
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'
|
// check 'v'
|
||||||
if v == nil {
|
if v == nil {
|
||||||
|
|
|
@ -10,14 +10,16 @@ var (
|
||||||
defaultIndent = "\t"
|
defaultIndent = "\t"
|
||||||
)
|
)
|
||||||
|
|
||||||
// encoder implements parser.Encoder
|
// Encoder implements parser.Encoder
|
||||||
type encoder struct {
|
type Encoder struct {
|
||||||
writer io.Writer
|
writer io.Writer
|
||||||
prefix []byte
|
prefix []byte
|
||||||
indent []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 = make([]byte, 0)
|
||||||
e.prefix = append(e.prefix, []byte(prefix)...)
|
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)...)
|
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
|
// default indentation
|
||||||
if e.prefix == nil || e.indent == nil {
|
if e.prefix == nil || e.indent == nil {
|
||||||
|
|
|
@ -5,11 +5,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewDecoder implements parser.T
|
// NewDecoder implements parser.T
|
||||||
func NewDecoder(r io.Reader) *decoder {
|
func NewDecoder(r io.Reader) *Decoder {
|
||||||
return &decoder{reader: r}
|
return &Decoder{reader: r}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewEncoder implements parser.T
|
// NewEncoder implements parser.T
|
||||||
func NewEncoder(w io.Writer) *encoder {
|
func NewEncoder(w io.Writer) *Encoder {
|
||||||
return &encoder{writer: w}
|
return &Encoder{writer: w}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue