Skip to content

Commit

Permalink
fixed linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyasnikov committed Apr 25, 2024
1 parent a4fb501 commit c81e704
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
16 changes: 2 additions & 14 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -287,25 +287,13 @@ issues:
# Show only new issues created in git patch with set file path.
# new-from-patch: path/to/patch/file
exclude-rules:
- path: internal/xatomic/type.go
- path: out_ydb.go
linters:
- predeclared
- gci
- path: _test\.go
linters:
- scopelint
- funlen
- unused
- unparam
- gocritic
- path: topic/topicreader/reader_example_test.go
linters:
- staticcheck
- path: _test\.go
text: "ydb.Connection is deprecated"
- path: examples
linters:
- gomnd

# Allow underscore and capital camel case for readability
# Examples: Type_PRIMITIVE_TYPE_ID_UNSPECIFIED, Ydb_Discovery_V1, _voidValue
- linters:
Expand Down
8 changes: 8 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ type credentialsDescription struct {

func isFile(path string) bool {
_, err := os.Stat(path)

return err == nil
}

Expand All @@ -46,6 +47,7 @@ var credentialsChooser = map[string]credentialsDescription{
if isFile(value) {
return yc.WithServiceAccountKeyFileCredentials(value), nil
}

return yc.WithServiceAccountKeyCredentials(value), nil
},
about: func() string {
Expand Down Expand Up @@ -75,6 +77,7 @@ var credentialsChooser = map[string]credentialsDescription{
if endpoint == "" {
return ydb.WithStaticCredentials(user, password), nil
}

return ydb.WithCredentials(credentials.NewStaticCredentials(user, password, endpoint)), nil
},
about: func() string {
Expand Down Expand Up @@ -125,6 +128,7 @@ func parseParamCredentialsStaticValue(value string) (user, password, endpoint st
user = u.User.Username()
password, _ = u.User.Password()
endpoint = u.Host

return
}

Expand Down Expand Up @@ -155,14 +159,17 @@ func ydbCredentials(plugin unsafe.Pointer) (c ydb.Option, err error) {
params = append(params, paramName)
}
sort.Strings(params)

return params
}(),
)
case 1:
for _, v := range creds {
c = v

break
}

return c, nil
default:
return nil, fmt.Errorf("require only one of credentials params: %v",
Expand All @@ -171,6 +178,7 @@ func ydbCredentials(plugin unsafe.Pointer) (c ydb.Option, err error) {
params = append(params, paramName)
}
sort.Strings(params)

return params
}(),
)
Expand Down
7 changes: 5 additions & 2 deletions internal/storage/ydb.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type YDB struct {
}

func New(cfg *config.Config) (*YDB, error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) //nolint:gomnd
defer cancel()

opts := []ydb.Option{cfg.CredentialsOption}
Expand Down Expand Up @@ -169,7 +169,7 @@ func (s *YDB) Write(events []*model.Event) error {
rows := make([]types.Value, 0, len(events))

for _, event := range events {
columns := make([]types.StructValueOption, 0, len(event.Message)+2)
columns := make([]types.StructValueOption, 0, len(event.Message)+2) //nolint:gomnd

v, err := type2Type(s.fieldMapping[config.KeyTimestamp].Type, event.Timestamp)
if err != nil {
Expand All @@ -187,6 +187,7 @@ func (s *YDB) Write(events []*model.Event) error {
column, exists := s.fieldMapping[field]
if !exists {
log.Warn(fmt.Sprintf("column for message key: %s (value: %s) not found, skip", field, value))

continue
}

Expand Down Expand Up @@ -256,13 +257,15 @@ func convertTypeIfOptional(t types.Type) (bool, types.Type) {
if optional {
return optional, inner
}

return false, t
}

func convertValueIfOptional(optional bool, v types.Value) types.Value {
if optional {
return types.OptionalValue(v)
}

return v
}

Expand Down
10 changes: 5 additions & 5 deletions internal/storage/ydb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/json"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
)

Expand Down Expand Up @@ -81,8 +81,8 @@ func TestConvertJson(t *testing.T) {

actual, err := json.Marshal(convertByteFieldsToString(v))

assert.NoError(t, err)
assert.Equal(t, expected, string(actual))
require.NoError(t, err)
require.Equal(t, expected, string(actual))
}

func TestType2TypeOk(t *testing.T) {
Expand Down Expand Up @@ -118,8 +118,8 @@ func TestType2TypeOk(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
actual, err := type2Type(tc.column, tc.value)

assert.NoError(t, err)
assert.Equal(t, actual, tc.expected)
require.NoError(t, err)
require.Equal(t, tc.expected, actual)
})
}
}
7 changes: 7 additions & 0 deletions out_ydb.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ func FLBPluginInit(plugin unsafe.Pointer) int {
cfg, err := config.ReadConfigFromPlugin(plugin)
if err != nil {
log.Error(fmt.Sprintf("failed read config: %v", err))

return output.FLB_ERROR
}

s, err := storage.New(&cfg)
if err != nil {
log.Error(fmt.Sprintf("failed create new storage: %v", err))

return output.FLB_ERROR
}

Expand Down Expand Up @@ -80,6 +82,7 @@ func FLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, tag *C.char) int
key, ok := k.(string)
if !ok {
log.Warn(fmt.Sprintf("unknown type of key '%+v'", k))

continue
}
message[key] = v
Expand All @@ -97,6 +100,7 @@ func FLBPluginFlushCtx(ctx, data unsafe.Pointer, length C.int, tag *C.char) int
err := s.Write(events)
if err != nil {
log.Error(fmt.Sprintf("write events failed: %v", err))

return output.FLB_ERROR
}

Expand All @@ -115,13 +119,16 @@ func FLBPluginExitCtx(ctx unsafe.Pointer) int {
})
if !ok {
log.Error("unknown storage object")

return output.FLB_ERROR
}
err := s.Exit()
if err != nil {
log.Error(fmt.Errorf("exit failed: %w", err).Error())

return output.FLB_ERROR
}

return output.FLB_OK
}

Expand Down

0 comments on commit c81e704

Please sign in to comment.