diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index e7c98bf..b698f40 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,7 +1,7 @@ name: Go on: push: - branches: [ main ] + branches: [main] paths: - '**.go' - 'go.mod' @@ -14,7 +14,7 @@ on: - '.golangci.yml' - '.github/workflows/go.yml' env: - GOPROXY: "https://proxy.golang.org" + GOPROXY: 'https://proxy.golang.org' jobs: lint: @@ -22,39 +22,31 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v2 - - name: Init Go Modules - run: | - go mod init github.com/go-ini/ini - go mod tidy + uses: actions/checkout@v6 + - name: Setup Go + uses: actions/setup-go@v6 + with: + go-version: stable - name: Run golangci-lint - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v9 with: version: latest args: --timeout=30m - skip-pkg-cache: true # Wrokaround of the "tar" problem: https://github.com/golangci/golangci-lint-action/issues/244 test: name: Test strategy: matrix: - go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x, 1.17.x, 1.18.x ] - platform: [ ubuntu-latest, macos-latest, windows-latest ] + go-version: [1.24.x, 1.25.x] + platform: [ubuntu-latest, macos-latest, windows-latest] runs-on: ${{ matrix.platform }} steps: - - name: Install Go - uses: actions/setup-go@v2 + - name: Checkout code + uses: actions/checkout@v6 + - name: Setup Go + uses: actions/setup-go@v6 with: go-version: ${{ matrix.go-version }} - - name: Checkout code - uses: actions/checkout@v2 - name: Run tests with coverage run: | - go mod init github.com/go-ini/ini - go mod tidy - go test -v -race -coverprofile=coverage -covermode=atomic ./... - - name: Upload coverage report to Codecov - uses: codecov/codecov-action@v1.5.0 - with: - file: ./coverage - flags: unittests + go test -v -race ./... diff --git a/.github/workflows/lsif.yml b/.github/workflows/lsif.yml deleted file mode 100644 index 58e4033..0000000 --- a/.github/workflows/lsif.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: LSIF -on: - push: - paths: - - '**.go' - - 'go.mod' - - '.github/workflows/lsif.yml' -env: - GOPROXY: "https://proxy.golang.org" - -jobs: - lsif-go: - if: github.repository == 'go-ini/ini' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - name: Generate LSIF data - uses: sourcegraph/lsif-go-action@master - - name: Upload LSIF data to sourcegraph.com - continue-on-error: true - uses: docker://sourcegraph/src-cli:latest - with: - args: lsif upload -github-token=${{ secrets.GITHUB_TOKEN }} - - name: Upload LSIF data to cs.unknwon.dev - continue-on-error: true - uses: docker://sourcegraph/src-cli:latest - with: - args: -endpoint=https://cs.unknwon.dev lsif upload -github-token=${{ secrets.GITHUB_TOKEN }} diff --git a/.golangci.yml b/.golangci.yml index 631e369..fabbdb6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,27 +1,36 @@ -linters-settings: - staticcheck: - checks: [ - "all", - "-SA1019" # There are valid use cases of strings.Title - ] - nakedret: - max-func-lines: 0 # Disallow any unnamed return statement - +version: "2" linters: enable: - - deadcode - - errcheck - - gosimple - - govet - - ineffassign - - staticcheck - - structcheck - - typecheck - - unused - - varcheck - nakedret - - gofmt - rowserrcheck - unconvert - - goimports - unparam + settings: + govet: + disable: + # printf: non-constant format string in call to fmt.Errorf (govet) + # showing up since golangci-lint version 1.60.1 + - printf + nakedret: + max-func-lines: 0 # Disallow any unnamed return statement + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/README.md b/README.md index 30606d9..e4c723d 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ # INI [![GitHub Workflow Status](https://img.shields.io/github/checks-status/go-ini/ini/main?logo=github&style=for-the-badge)](https://github.com/go-ini/ini/actions?query=branch%3Amain) -[![codecov](https://img.shields.io/codecov/c/github/go-ini/ini/master?logo=codecov&style=for-the-badge)](https://codecov.io/gh/go-ini/ini) [![GoDoc](https://img.shields.io/badge/GoDoc-Reference-blue?style=for-the-badge&logo=go)](https://pkg.go.dev/github.com/go-ini/ini?tab=doc) -[![Sourcegraph](https://img.shields.io/badge/view%20on-Sourcegraph-brightgreen.svg?style=for-the-badge&logo=sourcegraph)](https://sourcegraph.com/github.com/go-ini/ini) ![](https://avatars0.githubusercontent.com/u/10216035?v=3&s=200) @@ -27,10 +25,14 @@ Package ini provides INI file read and write functionality in Go. The minimum requirement of Go is **1.13**. ```sh -$ go get gopkg.in/ini.v1 +$ go get gopkg.in/ini.v1@latest ``` -Please add `-u` flag to update in the future. +> [!NOTE] +> If you previously used `github.com/go-ini/ini` as the import path in your project, without updating all of your code, you can use the following command to replace the import path in your `go.mod`: +> ```zsh +> go mod edit -replace github.com/go-ini/ini=gopkg.in/ini.v1@latest +> ``` ## Getting Help diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e3020b0 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module gopkg.in/ini.v1 + +go 1.13 + +require github.com/stretchr/testify v1.11.1 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..1cd876d --- /dev/null +++ b/go.sum @@ -0,0 +1,19 @@ +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/key.go b/key.go index a19d9f3..1a7767a 100644 --- a/key.go +++ b/key.go @@ -170,7 +170,7 @@ func (k *Key) transformValue(val string) string { } // Substitute by new value and take off leading '%(' and trailing ')s'. - val = strings.Replace(val, vr, nk.value, -1) + val = strings.ReplaceAll(val, vr, nk.value) } return val } @@ -429,7 +429,7 @@ func (k *Key) InUint64(defaultVal uint64, candidates []uint64) uint64 { func (k *Key) InTimeFormat(format string, defaultVal time.Time, candidates []time.Time) time.Time { val := k.MustTimeFormat(format) for _, cand := range candidates { - if val == cand { + if val.Equal(cand) { return val } } diff --git a/parser.go b/parser.go index 44fc526..73fb54d 100644 --- a/parser.go +++ b/parser.go @@ -130,13 +130,14 @@ func readKeyName(delimiters string, in []byte) (string, int, error) { // Check if key name surrounded by quotes. var keyQuote string - if line[0] == '"' { + switch line[0] { + case '"': if len(line) > 6 && line[0:3] == `"""` { keyQuote = `"""` } else { keyQuote = `"` } - } else if line[0] == '`' { + case '`': keyQuote = "`" } @@ -253,7 +254,7 @@ func (p *parser) readValue(in []byte, bufferSize int) (string, error) { } if p.options.UnescapeValueDoubleQuotes && valQuote == `"` { - return strings.Replace(line[startIdx:pos+startIdx], `\"`, `"`, -1), nil + return strings.ReplaceAll(line[startIdx:pos+startIdx], `\"`, `"`), nil } return line[startIdx : pos+startIdx], nil } diff --git a/struct_test.go b/struct_test.go index b51243a..ad6ad04 100644 --- a/struct_test.go +++ b/struct_test.go @@ -243,7 +243,7 @@ func Test_MapToStruct(t *testing.T) { assert.Equal(t, "[192.168 10.11]", fmt.Sprint(ts.Others.Coordinates)) assert.Equal(t, "[true false]", fmt.Sprint(ts.Others.Flags)) assert.Equal(t, "Hello world!", ts.Others.Note) - assert.Equal(t, 2.8, ts.TestEmbeded.GPA) + assert.Equal(t, 2.8, ts.GPA) assert.Equal(t, "HangZhou,Boston", strings.Join(ts.OthersPtr.Cities, ",")) assert.Equal(t, ti.String(), ts.OthersPtr.Visits[0].String())