From 01d05708d14aaad18bf23bc726bbd844bd01d89f Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Mon, 7 Sep 2026 23:29:30 +0200 Subject: [PATCH] Delete var --- .github/workflows/cloc.yml | 0 .github/workflows/golangci-lint.yml | 25 +++---------------------- .github/workflows/gorelease.yml | 0 .github/workflows/test-unit.yml | 0 .golangci.yml | 2 ++ Makefile | 2 +- go.mod | 2 +- go.sum | 4 ++-- vars.go | 11 +++++++++++ vars_test.go | 18 ++++++++++++++++++ 10 files changed, 38 insertions(+), 26 deletions(-) mode change 100755 => 100644 .github/workflows/cloc.yml mode change 100755 => 100644 .github/workflows/golangci-lint.yml mode change 100755 => 100644 .github/workflows/gorelease.yml mode change 100755 => 100644 .github/workflows/test-unit.yml diff --git a/.github/workflows/cloc.yml b/.github/workflows/cloc.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml old mode 100755 new mode 100644 index f435fe8..8d24825 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -21,28 +21,9 @@ jobs: steps: - uses: actions/setup-go@v5 with: - go-version: stable + go-version: oldstable - uses: actions/checkout@v4 - name: golangci-lint - uses: golangci/golangci-lint-action@v8.0.0 + uses: golangci/golangci-lint-action@v9.2.0 with: - # Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. - version: v2.4.0 - - # Optional: working directory, useful for monorepos - # working-directory: somedir - - # Optional: golangci-lint command line arguments. - # args: --issues-exit-code=0 - - # Optional: show only new issues if it's a pull request. The default value is `false`. - # only-new-issues: true - - # Optional: if set to true then the action will use pre-installed Go. - # skip-go-installation: true - - # Optional: if set to true then the action don't cache or restore ~/go/pkg. - # skip-pkg-cache: true - - # Optional: if set to true then the action don't cache or restore ~/.cache/go-build. - # skip-build-cache: true \ No newline at end of file + version: v2.11.3 diff --git a/.github/workflows/gorelease.yml b/.github/workflows/gorelease.yml old mode 100755 new mode 100644 diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml old mode 100755 new mode 100644 diff --git a/.golangci.yml b/.golangci.yml index a399ba1..0a528da 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,6 +5,8 @@ run: linters: default: all disable: + - embeddedstructfieldcheck + - nilnil - noinlineerr - wsl_v5 - funcorder diff --git a/Makefile b/Makefile index 2673221..47a73ec 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -#GOLANGCI_LINT_VERSION := "v2.5.0" # Optional configuration to pinpoint golangci-lint version. +#GOLANGCI_LINT_VERSION := "v2.11.3" # Optional configuration to pinpoint golangci-lint version. # The head of Makefile determines location of dev-go to include standard targets. GO ?= go diff --git a/go.mod b/go.mod index 8f62eb7..5ad580a 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bool64/shared go 1.17 require ( - github.com/bool64/dev v0.2.43 + github.com/bool64/dev v0.2.45 github.com/stretchr/testify v1.4.0 ) diff --git a/go.sum b/go.sum index 1c9bf86..9d5f72a 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/bool64/dev v0.2.43 h1:yQ7qiZVef6WtCl2vDYU0Y+qSq+0aBrQzY8KXkklk9cQ= -github.com/bool64/dev v0.2.43/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= +github.com/bool64/dev v0.2.45 h1:3nLKhAS/6Oklk3Mt2lHYSN/Cb4tdAD77KLwzeP+6eYE= +github.com/bool64/dev v0.2.45/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= 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= diff --git a/vars.go b/vars.go index 1c2065d..9d0cad6 100644 --- a/vars.go +++ b/vars.go @@ -111,6 +111,17 @@ func (v *Vars) Set(key string, val interface{}) { } } +// Delete removes variable by name. +// +// After Delete, Get reports the variable as not found, same as if it had +// never been set. +func (v *Vars) Delete(key string) { + v.mu.Lock() + defer v.mu.Unlock() + + delete(v.vars, key) +} + // OnSet adds callback to invoke when variable is set. // // All callbacks are removed on Reset. diff --git a/vars_test.go b/vars_test.go index b7061c0..1c4871f 100644 --- a/vars_test.go +++ b/vars_test.go @@ -35,6 +35,24 @@ func TestVars_GetAll(t *testing.T) { assert.Equal(t, map[string]interface{}{}, v.GetAll()) } +func TestVars_Delete(t *testing.T) { + v := shared.Vars{} + v.Set("k", "v") + v.Set("other", "unaffected") + + v.Delete("k") + + val, found := v.Get("k") + assert.False(t, found) + assert.Nil(t, val) + assert.Equal(t, map[string]interface{}{"other": "unaffected"}, v.GetAll()) + + // Deleting an already-absent (or never-set) key is a no-op, not an error. + v.Delete("k") + v.Delete("never-set") + assert.Equal(t, map[string]interface{}{"other": "unaffected"}, v.GetAll()) +} + func TestVars_Fork(t *testing.T) { v := shared.Vars{} v.Set("k", "v")