From 23e9fa323231c0841a913d4e2ad5c46667be0aa8 Mon Sep 17 00:00:00 2001 From: F Levanti Date: Wed, 16 Feb 2022 19:01:26 +0000 Subject: [PATCH 1/7] Fixed a small bug around skipCommits flag and added additional method to retrieve sections as a simple list --- ini.go | 14 +++++++++++++- ini_test.go | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ini.go b/ini.go index 11f405f..47b5b39 100644 --- a/ini.go +++ b/ini.go @@ -119,6 +119,18 @@ func (ini *INI) GetBool(key string) (bool, bool) { return ini.SectionGetBool(DefaultSection, key) } +// GetSectionsList returns the list of sections found in the parsed ini files +func (ini *INI) GetSectionsList() []string { + var l []string + for k := range ini.sections { + if k == "" { + continue + } + l = append(l, k) + } + return l +} + // SectionGet looks up a value for a key in a section // and returns that value, along with a boolean result similar to a map lookup. func (ini *INI) SectionGet(section, key string) (value string, ok bool) { @@ -294,7 +306,7 @@ func (ini *INI) parseINI(data []byte, lineSep, kvSep string) error { // Skip blank lines continue } - if ini.skipCommits && line[0] == ';' || line[0] == '#' { + if ini.skipCommits && (line[0] == ';' || line[0] == '#') { // Skip comments continue } diff --git a/ini_test.go b/ini_test.go index a76d795..4a9ad99 100644 --- a/ini_test.go +++ b/ini_test.go @@ -96,7 +96,9 @@ func Test1(t *testing.T) { b, ok = ini.GetBool("debug") assert.Equal(t, b, false) assert.Equal(t, ok, true) - + + l := ini.GetSectionsList() + assert.Equal(t, len(l), 2) } func Test2(t *testing.T) { From 85fd750e2a916e234eefdb224bf1fa8b08562974 Mon Sep 17 00:00:00 2001 From: "F. Levanti" Date: Wed, 16 Feb 2022 19:03:55 +0000 Subject: [PATCH 2/7] code formatting --- ini_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ini_test.go b/ini_test.go index 4a9ad99..51a2183 100644 --- a/ini_test.go +++ b/ini_test.go @@ -97,7 +97,7 @@ func Test1(t *testing.T) { assert.Equal(t, b, false) assert.Equal(t, ok, true) - l := ini.GetSectionsList() + l := ini.GetSectionsList() assert.Equal(t, len(l), 2) } From c6378c72765ae8640adf978a6be632ff0aed8c7c Mon Sep 17 00:00:00 2001 From: F Levanti Date: Wed, 16 Feb 2022 19:12:48 +0000 Subject: [PATCH 3/7] module files --- go.mod | 14 ++++++++++++++ go.sum | 16 ++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 go.mod create mode 100644 go.sum diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e7e67fc --- /dev/null +++ b/go.mod @@ -0,0 +1,14 @@ +module goini + +go 1.17 + +require ( + github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 + github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26 +) + +require ( + github.com/kr/pretty v0.3.0 // indirect + github.com/kr/text v0.2.0 // indirect + github.com/rogpeppe/go-internal v1.6.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..2b2f7fc --- /dev/null +++ b/go.sum @@ -0,0 +1,16 @@ +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 h1:DDGfHa7BWjL4YnC6+E63dPcxHo2sUxDIu8g3QgEJdRY= +github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26 h1:E0lEWrifmR0ACbGf5PLji1XbW6rtIXLHCXO/YOqi0AE= +github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26/go.mod h1:TQpdgg7I9+PFIkatlx/dnZyZb4iZyCUx1HJj4rXi3+E= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= From 7bd319c741eb14756150eb2b41806acba434da73 Mon Sep 17 00:00:00 2001 From: F Levanti Date: Wed, 16 Feb 2022 19:20:15 +0000 Subject: [PATCH 4/7] mod files tidy up --- go.mod | 7 ++----- go.sum | 2 -- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/go.mod b/go.mod index e7e67fc..b74f600 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,8 @@ -module goini +module github.com/zieckey/goini go 1.17 -require ( - github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 - github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26 -) +require github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 require ( github.com/kr/pretty v0.3.0 // indirect diff --git a/go.sum b/go.sum index 2b2f7fc..ac64d1f 100644 --- a/go.sum +++ b/go.sum @@ -10,7 +10,5 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26 h1:E0lEWrifmR0ACbGf5PLji1XbW6rtIXLHCXO/YOqi0AE= -github.com/zieckey/goini v0.0.0-20180118150432-0da17d361d26/go.mod h1:TQpdgg7I9+PFIkatlx/dnZyZb4iZyCUx1HJj4rXi3+E= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= From 2f52bdbd9d1f65aa8dd096a8c9440c212b8311a6 Mon Sep 17 00:00:00 2001 From: F Levanti Date: Thu, 24 Feb 2022 08:48:31 +0000 Subject: [PATCH 5/7] changing module name and updating readme file --- README.md | 8 +++++--- examples/ini_file_parsing/main.go | 7 +++---- examples/memory_ini_data_parsing/main.go | 3 ++- go.mod | 7 +++++-- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index bb2effa..907a7f7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ ## goini -[![Build Status](https://secure.travis-ci.org/zieckey/goini.png)](http://travis-ci.org/zieckey/goini) [![Coverage Status](https://img.shields.io/coveralls/zieckey/goini.svg)](https://coveralls.io/r/zieckey/goini?branch=master) +This repository has been forked from github.com/zieckey/goini + +It fixes a bug (https://github.com/zieckey/goini/issues/4) and offers a method to retrieve the ini configuration sections as a list. This is a Go package to interact with arbitrary INI. @@ -22,7 +24,7 @@ I have not found any Golang open source code suitable for it. So I write it myse ## Importing - import github.com/zieckey/goini + import github.com/flevanti/goini ## Usage @@ -30,7 +32,7 @@ I have not found any Golang open source code suitable for it. So I write it myse The simplest example code is : ```go -import github.com/zieckey/goini +import github.com/flevanti/goini ini := goini.New() err := ini.ParseFile(filename) diff --git a/examples/ini_file_parsing/main.go b/examples/ini_file_parsing/main.go index 15307e0..3ab28ff 100644 --- a/examples/ini_file_parsing/main.go +++ b/examples/ini_file_parsing/main.go @@ -8,7 +8,7 @@ import ( "fmt" "path/filepath" - "github.com/zieckey/goini" + "github.com/flevanti/goini" ) func main() { @@ -33,17 +33,16 @@ func main() { fmt.Printf("sss size is invalid\n") return } - + v, ok = ini.SectionGet("sss", "aa") if !ok || v != "bb" { fmt.Printf("sss/aa value is invalid\n") return } - + v, ok = ini.SectionGet("sss", "appext") if !ok || v != "ab=cd" { fmt.Printf("sss/appext value is invalid\n") return } } - diff --git a/examples/memory_ini_data_parsing/main.go b/examples/memory_ini_data_parsing/main.go index c764c10..d402c99 100644 --- a/examples/memory_ini_data_parsing/main.go +++ b/examples/memory_ini_data_parsing/main.go @@ -6,7 +6,8 @@ package main import ( "fmt" - "github.com/zieckey/goini" + + "github.com/flevanti/goini" ) func f1() { diff --git a/go.mod b/go.mod index b74f600..5f55532 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,11 @@ -module github.com/zieckey/goini +module goini go 1.17 -require github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 +require ( + github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 + github.com/flevanti/goini v0.0.0-00010101000000-000000000000 +) require ( github.com/kr/pretty v0.3.0 // indirect From 4933a24d4af4034cfbef95d312abdeb45acfa4d7 Mon Sep 17 00:00:00 2001 From: F Levanti Date: Thu, 24 Feb 2022 09:00:16 +0000 Subject: [PATCH 6/7] fixin mod files issue --- go.mod | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 5f55532..91bdb25 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,8 @@ -module goini +module github.com/flevanti/goini go 1.17 -require ( - github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 - github.com/flevanti/goini v0.0.0-00010101000000-000000000000 -) +require github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 require ( github.com/kr/pretty v0.3.0 // indirect From 2392117839d6eae357fb4c8e40add4673ee711f2 Mon Sep 17 00:00:00 2001 From: FLevanti Date: Sat, 26 Feb 2022 15:29:09 +0000 Subject: [PATCH 7/7] updated gitingnore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 1cbede1..719b683 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ coverage.out examples/ini_file_parsing/ini_file_parsing examples/inherited_ini_parsing/inherited_ini_parsing examples/memory_ini_data_parsing/memory_ini_data_parsing +.idea