Skip to content

Commit 892394e

Browse files
authored
chore: upgrade go to 1.26 and tidy go.mod (#1066)
1 parent 2d2e1f3 commit 892394e

28 files changed

+1256
-408
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@ jobs:
5757
permissions: {}
5858
steps:
5959
- name: Set up Go
60-
uses: actions/setup-go@v4
60+
uses: actions/setup-go@v6
6161
with:
62-
go-version: 1.18
62+
go-version: '1.26'
6363
- name: Checkout
6464
uses: actions/checkout@v5
6565
- name: golangci-lint
66-
uses: golangci/golangci-lint-action@v3
67-
with:
68-
version: v1.45.2
66+
uses: golangci/golangci-lint-action@v9
6967

7068
test:
7169
runs-on: ubuntu-latest
@@ -74,9 +72,9 @@ jobs:
7472
- lint
7573
steps:
7674
- name: Set up Go
77-
uses: actions/setup-go@v4
75+
uses: actions/setup-go@v6
7876
with:
79-
go-version: 1.18
77+
go-version: '1.26'
8078
- name: Checkout
8179
uses: actions/checkout@v5
8280
- name: Cache Go modules
@@ -106,9 +104,9 @@ jobs:
106104
steps:
107105
# Setup Go and checkout
108106
- name: Set up Go
109-
uses: actions/setup-go@v4
107+
uses: actions/setup-go@v6
110108
with:
111-
go-version: 1.18
109+
go-version: '1.26'
112110
- name: Checkout
113111
uses: actions/checkout@v5
114112
- name: Cache Go modules
@@ -208,9 +206,9 @@ jobs:
208206
- lint
209207
steps:
210208
- name: Set up Go
211-
uses: actions/setup-go@v4
209+
uses: actions/setup-go@v6
212210
with:
213-
go-version: 1.18
211+
go-version: '1.26'
214212
- name: Checkout
215213
uses: actions/checkout@v5
216214
- name: Cache Go modules

.golangci.yml

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
1-
run:
2-
skip-dirs-use-default: false
1+
version: '2'
32

43
linters:
4+
settings:
5+
lll:
6+
line-length: 80
7+
tab-width: 4
58
enable:
6-
- deadcode
79
- errcheck
8-
- gosimple
910
- govet
10-
- ineffassign
1111
- staticcheck
12-
- structcheck
13-
- typecheck
12+
- ineffassign
1413
- unused
15-
- varcheck
16-
- errchkjson
17-
- errorlint
18-
- godot
19-
- gofmt
20-
- goimports
21-
- misspell
22-
- prealloc
23-
- revive
24-
- unconvert
25-
- whitespace
14+
- lll
2615

27-
issues:
28-
include:
29-
- EXC0002
16+
formatters:
17+
enable:
18+
- gofumpt
19+
- golines
20+
- gci
21+
settings:
22+
golines:
23+
max-len: 80
24+
tab-len: 4
25+
shorten-comments: true
26+
reformat-tags: false
27+
gci:
28+
sections:
29+
- standard
30+
- default
31+
- prefix(github.com/loderunner/scrt)

backend/git.go

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"context"
1919
"errors"
2020
"fmt"
21-
"io/ioutil"
21+
"io"
2222
"os"
2323
"time"
2424

@@ -42,10 +42,26 @@ const defaultCommitMessage = "update secrets"
4242
func init() {
4343
gitFlagSet = pflag.NewFlagSet("git", pflag.ContinueOnError)
4444
gitFlagSet.String("git-url", "", "URL of the git repository (required)")
45-
gitFlagSet.String("git-path", "", "path of the store in the repository (required)")
46-
gitFlagSet.String("git-branch", "", "branch to checkout, commit and push to on updates")
47-
gitFlagSet.String("git-checkout", "", "tree-ish revision to checkout, e.g. commit or tag")
48-
gitFlagSet.String("git-message", "", "commit message when updating the store")
45+
gitFlagSet.String(
46+
"git-path",
47+
"",
48+
"path of the store in the repository (required)",
49+
)
50+
gitFlagSet.String(
51+
"git-branch",
52+
"",
53+
"branch to checkout, commit and push to on updates",
54+
)
55+
gitFlagSet.String(
56+
"git-checkout",
57+
"",
58+
"tree-ish revision to checkout, e.g. commit or tag",
59+
)
60+
gitFlagSet.String(
61+
"git-message",
62+
"",
63+
"commit message when updating the store",
64+
)
4965
}
5066

5167
type gitBackend struct {
@@ -61,7 +77,10 @@ func (f gitFactory) New(conf map[string]interface{}) (Backend, error) {
6177
return f.NewContext(context.Background(), conf)
6278
}
6379

64-
func (f gitFactory) NewContext(ctx context.Context, conf map[string]interface{}) (Backend, error) {
80+
func (f gitFactory) NewContext(
81+
ctx context.Context,
82+
conf map[string]interface{},
83+
) (Backend, error) {
6584
return newGit(ctx, conf)
6685
}
6786

@@ -90,7 +109,11 @@ func newGit(ctx context.Context, conf map[string]interface{}) (Backend, error) {
90109
}
91110
url, ok := opt.(string)
92111
if !ok {
93-
return nil, fmt.Errorf("repository URL is not a string: (%T)%s", opt, opt)
112+
return nil, fmt.Errorf(
113+
"repository URL is not a string: (%T)%s",
114+
opt,
115+
opt,
116+
)
94117
}
95118
logger = logger.WithField("url", url)
96119

@@ -163,6 +186,7 @@ func newGit(ctx context.Context, conf map[string]interface{}) (Backend, error) {
163186
func (g gitBackend) Exists() (bool, error) {
164187
return g.ExistsContext(context.Background())
165188
}
189+
166190
func (g gitBackend) ExistsContext(ctx context.Context) (bool, error) {
167191
logger := getLogger(ctx)
168192

@@ -183,17 +207,18 @@ func (g gitBackend) ExistsContext(ctx context.Context) (bool, error) {
183207
func (g gitBackend) Save(data []byte) error {
184208
return g.SaveContext(context.Background(), data)
185209
}
210+
186211
func (g gitBackend) SaveContext(ctx context.Context, data []byte) error {
187212
logger := getLogger(ctx)
188213

189214
logger = logger.WithField("path", g.path)
190215

191216
logger.Info("opening file in git repository")
192-
f, err := g.fs.OpenFile(g.path, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0700)
217+
f, err := g.fs.OpenFile(g.path, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0o700)
193218
if err != nil {
194219
return err
195220
}
196-
defer f.Close()
221+
defer func() { _ = f.Close() }()
197222

198223
logger.Info("writing encrypted data to git repository")
199224
n, err := f.Write(data)
@@ -232,7 +257,10 @@ func (g gitBackend) SaveContext(ctx context.Context, data []byte) error {
232257
}
233258

234259
logger.
235-
WithField("committer", fmt.Sprintf("%s <%s>", authorCommitter.Name, authorCommitter.Email)).
260+
WithField(
261+
"committer",
262+
fmt.Sprintf("%s <%s>", authorCommitter.Name, authorCommitter.Email),
263+
).
236264
Infof("committing changes to git repository: \"%s\"", g.message)
237265
_, err = w.Commit(
238266
g.message,
@@ -259,6 +287,7 @@ func (g gitBackend) SaveContext(ctx context.Context, data []byte) error {
259287
func (g gitBackend) Load() ([]byte, error) {
260288
return g.LoadContext(context.Background())
261289
}
290+
262291
func (g gitBackend) LoadContext(ctx context.Context) ([]byte, error) {
263292
logger := getLogger(ctx)
264293

@@ -270,9 +299,9 @@ func (g gitBackend) LoadContext(ctx context.Context) ([]byte, error) {
270299
if err != nil {
271300
return nil, err
272301
}
273-
defer f.Close()
302+
defer func() { _ = f.Close() }()
274303

275-
data, err := ioutil.ReadAll(f)
304+
data, err := io.ReadAll(f)
276305
if err != nil {
277306
return nil, err
278307
}

backend/local.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ var localFlagSet *pflag.FlagSet
2929

3030
func init() {
3131
localFlagSet = pflag.NewFlagSet("local", pflag.ContinueOnError)
32-
localFlagSet.String("local-path", "", "path to the store in the local filesystem (required)")
32+
localFlagSet.String(
33+
"local-path",
34+
"",
35+
"path to the store in the local filesystem (required)",
36+
)
3337
}
3438

3539
type local struct {
@@ -42,7 +46,11 @@ type localFactory struct{}
4246
func (f localFactory) New(conf map[string]interface{}) (Backend, error) {
4347
return f.NewContext(context.Background(), conf)
4448
}
45-
func (f localFactory) NewContext(ctx context.Context, conf map[string]interface{}) (Backend, error) {
49+
50+
func (f localFactory) NewContext(
51+
ctx context.Context,
52+
conf map[string]interface{},
53+
) (Backend, error) {
4654
return newLocal(ctx, conf)
4755
}
4856

@@ -62,7 +70,10 @@ func init() {
6270
Backends["local"] = localFactory{}
6371
}
6472

65-
func newLocal(ctx context.Context, conf map[string]interface{}) (Backend, error) {
73+
func newLocal(
74+
ctx context.Context,
75+
conf map[string]interface{},
76+
) (Backend, error) {
6677
logger := getLogger(ctx)
6778

6879
opt := readOpt("local", "path", conf)
@@ -114,8 +125,9 @@ func (l local) Save(data []byte) error {
114125

115126
func (l local) SaveContext(ctx context.Context, data []byte) error {
116127
logger := getLogger(ctx)
117-
logger.WithField("path", l.path).Info("writing encrypted data to local storage")
118-
return afero.WriteFile(l.fs, l.path, data, 0600)
128+
logger.WithField("path", l.path).
129+
Info("writing encrypted data to local storage")
130+
return afero.WriteFile(l.fs, l.path, data, 0o600)
119131
}
120132

121133
func (l local) Load() ([]byte, error) {
@@ -124,6 +136,7 @@ func (l local) Load() ([]byte, error) {
124136

125137
func (l local) LoadContext(ctx context.Context) ([]byte, error) {
126138
logger := getLogger(ctx)
127-
logger.WithField("path", l.path).Info("reading encrypted data from local storage")
139+
logger.WithField("path", l.path).
140+
Info("reading encrypted data from local storage")
128141
return afero.ReadFile(l.fs, l.path)
129142
}

backend/local_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,21 @@ import (
1919
"reflect"
2020
"testing"
2121

22-
"github.com/loderunner/scrt/store"
2322
"github.com/spf13/afero"
23+
24+
"github.com/loderunner/scrt/store"
2425
)
2526

2627
func TestLocalExists(t *testing.T) {
2728
path := "/tmp/store.scrt"
2829
fs := afero.NewMemMapFs()
29-
f, err := fs.OpenFile(path, os.O_CREATE, 0600)
30+
f, err := fs.OpenFile(path, os.O_CREATE, 0o600)
3031
if err != nil {
3132
t.Fatal(err)
3233
}
33-
f.Close()
34+
if err = f.Close(); err != nil {
35+
t.Fatal(err)
36+
}
3437

3538
b := local{path: "/tmp/nonexistent.scrt", fs: fs}
3639
exists, err := b.Exists()

backend/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ type Backend interface {
4848
type Factory interface {
4949
// New returns an initialized backend from the given configuration
5050
New(conf map[string]interface{}) (Backend, error)
51-
NewContext(ctx context.Context, conf map[string]interface{}) (Backend, error)
51+
NewContext(
52+
ctx context.Context,
53+
conf map[string]interface{},
54+
) (Backend, error)
5255

5356
// Name returns a human-readable name for the backend
5457
Name() string

0 commit comments

Comments
 (0)