Compare commits
No commits in common. "081139cf6595cb647b017ad88ccd862b48a4d69b" and "fdf99daa9cbd9ac1c7a12476f55ebb71f8ed2831" have entirely different histories.
081139cf65
...
fdf99daa9c
4 changed files with 9 additions and 43 deletions
|
@ -1,22 +0,0 @@
|
||||||
on: [push]
|
|
||||||
jobs:
|
|
||||||
linting:
|
|
||||||
runs-on: docker
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: stable
|
|
||||||
- uses: https://github.com/golangci/golangci-lint-action@v6
|
|
||||||
tests:
|
|
||||||
runs-on: docker
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- uses: actions/setup-go@v5
|
|
||||||
with:
|
|
||||||
go-version: stable
|
|
||||||
- name: Install dependencies
|
|
||||||
run: go get .
|
|
||||||
- name: Run tests
|
|
||||||
run: go test
|
|
||||||
|
|
|
@ -435,13 +435,10 @@ linters:
|
||||||
- github.com/alexedwards/argon2id
|
- github.com/alexedwards/argon2id
|
||||||
- github.com/google/uuid
|
- github.com/google/uuid
|
||||||
- github.com/hack-pad/hackpadfs
|
- github.com/hack-pad/hackpadfs
|
||||||
- github.com/hashicorp/hcl/v2
|
|
||||||
- github.com/jessevdk/go-flags
|
- github.com/jessevdk/go-flags
|
||||||
- github.com/pelletier/go-toml/v2
|
|
||||||
- github.com/pressly/goose/v3
|
- github.com/pressly/goose/v3
|
||||||
- github.com/PuerkitoBio/goquery
|
- github.com/PuerkitoBio/goquery
|
||||||
- github.com/stretchr/testify
|
- github.com/stretchr/testify
|
||||||
- gopkg.in/ini.v1
|
|
||||||
- gopkg.in/yaml.v3
|
- gopkg.in/yaml.v3
|
||||||
- modernc.org/sqlite
|
- modernc.org/sqlite
|
||||||
# List of allowed module domains.
|
# List of allowed module domains.
|
||||||
|
@ -2709,7 +2706,7 @@ linters:
|
||||||
- path: _test\.go
|
- path: _test\.go
|
||||||
linters:
|
linters:
|
||||||
- revive
|
- revive
|
||||||
text: "(comments-density|line-length-limit|unchecked-type-assertion|cognitive-complexity)"
|
text: "(comments-density|line-length-limit|unchecked-type-assertion)"
|
||||||
|
|
||||||
# Run some linter only for test files by excluding its issues for everything else.
|
# Run some linter only for test files by excluding its issues for everything else.
|
||||||
#- path-except: _test\.go
|
#- path-except: _test\.go
|
||||||
|
|
23
adapters.go
23
adapters.go
|
@ -18,8 +18,6 @@ import (
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
const errMsgConfigGen = "cannot generate config content: %w"
|
|
||||||
|
|
||||||
func parseError(err error) error {
|
func parseError(err error) error {
|
||||||
return fmt.Errorf("cannot parse config file: %w", err)
|
return fmt.Errorf("cannot parse config file: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -107,7 +105,7 @@ func unmarshalJSON(data []byte, v any) error {
|
||||||
func marshalJSON(v any) ([]byte, error) {
|
func marshalJSON(v any) ([]byte, error) {
|
||||||
data, err := json.MarshalIndent(v, "", " ")
|
data, err := json.MarshalIndent(v, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(errMsgConfigGen, err)
|
return nil, fmt.Errorf("cannot generate config content: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
|
@ -127,7 +125,7 @@ func unmarshalTOML(data []byte, v any) error {
|
||||||
func marshalTOML(v any) ([]byte, error) {
|
func marshalTOML(v any) ([]byte, error) {
|
||||||
data, err := toml.Marshal(v)
|
data, err := toml.Marshal(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(errMsgConfigGen, err)
|
return nil, fmt.Errorf("cannot generate config content: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
|
@ -187,7 +185,7 @@ func unmarshalYAML(data []byte, v any) error {
|
||||||
func marshalYAML(v any) ([]byte, error) {
|
func marshalYAML(v any) ([]byte, error) {
|
||||||
data, err := yaml.Marshal(v)
|
data, err := yaml.Marshal(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf(errMsgConfigGen, err)
|
return nil, fmt.Errorf("cannot generate config content: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
|
@ -196,7 +194,6 @@ func marshalYAML(v any) ([]byte, error) {
|
||||||
// unmarshalINI unmarshals the given data to the given struct.
|
// unmarshalINI unmarshals the given data to the given struct.
|
||||||
func unmarshalINI(data []byte, v any) error {
|
func unmarshalINI(data []byte, v any) error {
|
||||||
opts := ini.LoadOptions{}
|
opts := ini.LoadOptions{}
|
||||||
|
|
||||||
cfg, err := ini.LoadSources(opts, data)
|
cfg, err := ini.LoadSources(opts, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return parseError(err)
|
return parseError(err)
|
||||||
|
@ -223,31 +220,25 @@ func marshalINI(v any) ([]byte, error) {
|
||||||
|
|
||||||
err := ini.ReflectFromWithMapper(cfg, v, iniNameMapper)
|
err := ini.ReflectFromWithMapper(cfg, v, iniNameMapper)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("cannot generate config from struct: %w", err)
|
return nil, fmt.Errorf("cannot generate config content: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
cfg.WriteTo(&buf)
|
||||||
|
data := buf.Bytes()
|
||||||
|
|
||||||
_, err = cfg.WriteTo(&buf)
|
return data, nil
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf(errMsgConfigGen, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf.Bytes(), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func iniNameMapper(raw string) string {
|
func iniNameMapper(raw string) string {
|
||||||
newstr := make([]rune, 0, len(raw))
|
newstr := make([]rune, 0, len(raw))
|
||||||
|
|
||||||
for i, chr := range raw {
|
for i, chr := range raw {
|
||||||
if isUpper := 'A' <= chr && chr <= 'Z'; isUpper {
|
if isUpper := 'A' <= chr && chr <= 'Z'; isUpper {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
newstr = append(newstr, '_')
|
newstr = append(newstr, '_')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newstr = append(newstr, unicode.ToLower(chr))
|
newstr = append(newstr, unicode.ToLower(chr))
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(newstr)
|
return string(newstr)
|
||||||
}
|
}
|
||||||
|
|
|
@ -241,7 +241,7 @@ func testLoadFiles(t *testing.T, ext string) {
|
||||||
err := conf.LoadFiles(&c, "test_data/invalid."+ext, "test_data/valid."+ext)
|
err := conf.LoadFiles(&c, "test_data/invalid."+ext, "test_data/valid."+ext)
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
|
|
||||||
assert.Empty(t, c.String)
|
assert.Equal(t, "", c.String)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("with a valid file and invalid data", func(t *testing.T) {
|
t.Run("with a valid file and invalid data", func(t *testing.T) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue