From 40d6526b64acfa12aec717f91733f90c4725cd64 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 11 Nov 2018 15:34:00 +0100 Subject: [PATCH] unexport cnf/Json to json and cnf/Ini to ini --- internal/cnf/ini.go | 16 ++++++++-------- internal/cnf/ini_test.go | 6 +++--- internal/cnf/json.go | 18 +++++++++--------- internal/cnf/json_test.go | 8 ++++---- internal/cnf/loader.go | 4 ++-- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/internal/cnf/ini.go b/internal/cnf/ini.go index fca7111..4955025 100644 --- a/internal/cnf/ini.go +++ b/internal/cnf/ini.go @@ -1,23 +1,23 @@ package cnf import ( - "github.com/go-ini/ini" + lib "github.com/go-ini/ini" "io" "io/ioutil" "strings" ) -type Ini struct { +type ini struct { sections []string - data *ini.File + data *lib.File parsed bool } // ReadFrom implements io.ReaderFrom -func (d *Ini) ReadFrom(_reader io.Reader) (int64, error) { +func (d *ini) ReadFrom(_reader io.Reader) (int64, error) { // 1. get json decoder - file, err := ini.Load(ioutil.NopCloser(_reader)) + file, err := lib.Load(ioutil.NopCloser(_reader)) if err != nil { return 0, err } @@ -30,13 +30,13 @@ func (d *Ini) ReadFrom(_reader io.Reader) (int64, error) { } // WriteTo implements io.WriterTo -func (d *Ini) WriteTo(_writer io.Writer) (int64, error) { +func (d *ini) WriteTo(_writer io.Writer) (int64, error) { return d.data.WriteTo(_writer) } // Get returns the value of a dot-separated path, and if it exists // the maximum depth is 2 : Section.Field -func (d *Ini) Get(_path string) (string, bool) { +func (d *ini) Get(_path string) (string, bool) { // 1. split path path := strings.Split(_path, ".") @@ -80,7 +80,7 @@ func (d *Ini) Get(_path string) (string, bool) { } // Set the value of a dot-separated path, and creates it if not found -func (d *Ini) Set(_path, _value string) bool { +func (d *ini) Set(_path, _value string) bool { // 1. split path path := strings.Split(_path, ".") diff --git a/internal/cnf/ini_test.go b/internal/cnf/ini_test.go index a6a489a..03ae4fd 100644 --- a/internal/cnf/ini_test.go +++ b/internal/cnf/ini_test.go @@ -18,7 +18,7 @@ func TestIniGet(t *testing.T) { for _, test := range tests { - parser := new(Ini) + parser := new(ini) reader := bytes.NewBufferString(test.raw) // try to extract value @@ -58,7 +58,7 @@ func TestIniSetPathExists(t *testing.T) { for _, test := range tests { - parser := new(Ini) + parser := new(ini) reader := bytes.NewBufferString(test.raw) // try to extract value @@ -106,7 +106,7 @@ func TestIniSetCreatePath(t *testing.T) { for i, test := range tests { - parser := new(Ini) + parser := new(ini) reader := bytes.NewBufferString(test.raw) // try to extract value diff --git a/internal/cnf/json.go b/internal/cnf/json.go index 132ccd2..a807860 100644 --- a/internal/cnf/json.go +++ b/internal/cnf/json.go @@ -1,21 +1,21 @@ package cnf import ( - "encoding/json" + lib "encoding/json" "io" "strings" ) -type Json struct { +type json struct { data interface{} parsed bool } // ReadFrom implements io.ReaderFrom -func (d *Json) ReadFrom(_reader io.Reader) (int64, error) { +func (d *json) ReadFrom(_reader io.Reader) (int64, error) { // 1. get json decoder - decoder := json.NewDecoder(_reader) + decoder := lib.NewDecoder(_reader) err := decoder.Decode(&d.data) if err != nil { return 0, err @@ -27,14 +27,14 @@ func (d *Json) ReadFrom(_reader io.Reader) (int64, error) { } // WriteTo implements io.WriterTo -func (d *Json) WriteTo(_writer io.Writer) (int64, error) { - encoder := json.NewEncoder(_writer) +func (d *json) WriteTo(_writer io.Writer) (int64, error) { + encoder := lib.NewEncoder(_writer) encoder.SetIndent("", "\t") return 0, encoder.Encode(&d.data) } // browse returns the target of a dot-separated path (as an interface{} chain where the last is the target if found) -func (d *Json) browse(_path string) ([]interface{}, bool) { +func (d *json) browse(_path string) ([]interface{}, bool) { // 1. extract path path := strings.Split(_path, ".") @@ -64,7 +64,7 @@ func (d *Json) browse(_path string) ([]interface{}, bool) { } // Get returns the value of a dot-separated path, and if it exists -func (d *Json) Get(_path string) (string, bool) { +func (d *json) Get(_path string) (string, bool) { // 1. browse path chain, found := d.browse(_path) @@ -79,7 +79,7 @@ func (d *Json) Get(_path string) (string, bool) { } // Set the value of a dot-separated path, and creates it if not found -func (d *Json) Set(_path, _value string) bool { +func (d *json) Set(_path, _value string) bool { // 1. browse path + create it if does not exist path := strings.Split(_path, ".") diff --git a/internal/cnf/json_test.go b/internal/cnf/json_test.go index 8c7d390..70f5346 100644 --- a/internal/cnf/json_test.go +++ b/internal/cnf/json_test.go @@ -19,7 +19,7 @@ func TestJsonGet(t *testing.T) { for _, test := range tests { - parser := new(Json) + parser := new(json) reader := bytes.NewBufferString(test.raw) // try to extract value @@ -59,7 +59,7 @@ func TestJsonGetNotString(t *testing.T) { for _, test := range tests { - parser := new(Json) + parser := new(json) reader := bytes.NewBufferString(test.raw) // try to extract value @@ -95,7 +95,7 @@ func TestJsonSetPathExistsAndIsString(t *testing.T) { for _, test := range tests { - parser := new(Json) + parser := new(json) reader := bytes.NewBufferString(test.raw) // try to extract value @@ -146,7 +146,7 @@ func TestJsonSetCreatePath(t *testing.T) { for i, test := range tests { - parser := new(Json) + parser := new(json) reader := bytes.NewBufferString(test.raw) // try to extract value diff --git a/internal/cnf/loader.go b/internal/cnf/loader.go index dadce5a..913cfa1 100644 --- a/internal/cnf/loader.go +++ b/internal/cnf/loader.go @@ -68,9 +68,9 @@ func loadFromExtension(ext string) ConfigurationFormat { // select configuration or fail if not known switch ext { case ".json": - return new(Json) + return new(json) case ".ini": - return new(Ini) + return new(ini) default: return nil }