Skip to content

Commit

Permalink
fixing linting
Browse files Browse the repository at this point in the history
Signed-off-by: Chengxuan Xing <[email protected]>
  • Loading branch information
Chengxuan committed Dec 9, 2024
1 parent 9aee2fd commit 1cf8bf2
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pkg/ffapi/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ func (hs *HandlerFactory) handleOutput(ctx context.Context, res http.ResponseWri
}
if marshalErr != nil {
err := i18n.WrapError(ctx, marshalErr, i18n.MsgResponseMarshalError)
log.L(ctx).Errorf(err.Error())
log.L(ctx).Error(err.Error())
return 500, err
}
return status, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/ffapi/openapi3.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ func (sg *SwaggerGen) addRoute(ctx context.Context, doc *openapi3.T, route *Rout
} else {
routeDescription = i18n.Expand(ctx, route.Description)
if routeDescription == "" && sg.options.PanicOnMissingDescription {
log.Panicf(i18n.NewError(ctx, i18n.MsgRouteDescriptionMissing, route.Name).Error())
log.Panic(i18n.NewError(ctx, i18n.MsgRouteDescriptionMissing, route.Name).Error())
}
}
op := &openapi3.Operation{
Expand Down
19 changes: 16 additions & 3 deletions pkg/ffapi/query_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"database/sql/driver"
"encoding/json"
"fmt"
"math"
"math/big"
"reflect"
"strconv"
Expand Down Expand Up @@ -110,11 +111,11 @@ func (f *stringField) Scan(src interface{}) error {
case int64:
f.s = strconv.FormatInt(tv, 10)
case uint:
f.s = strconv.FormatInt(int64(tv), 10)
f.s = strconv.FormatUint(uint64(tv), 10)
case uint32:
f.s = strconv.FormatInt(int64(tv), 10)
f.s = strconv.FormatUint(uint64(tv), 10)
case uint64:
f.s = strconv.FormatInt(int64(tv), 10)
f.s = strconv.FormatUint(tv, 10)
case *fftypes.UUID:
if tv != nil {
f.s = tv.String()
Expand Down Expand Up @@ -242,10 +243,16 @@ func (f *int64Field) Scan(src interface{}) (err error) {
case int64:
f.i = tv
case uint:
if tv > math.MaxInt64 {
return i18n.NewError(context.Background(), i18n.MsgTypeRestoreFailed, src, f.i)
}
f.i = int64(tv)
case uint32:
f.i = int64(tv)
case uint64:
if tv > math.MaxInt64 {
return i18n.NewError(context.Background(), i18n.MsgTypeRestoreFailed, src, f.i)
}
f.i = int64(tv)
case string:
f.i, err = strconv.ParseInt(src.(string), 10, 64)
Expand Down Expand Up @@ -277,10 +284,16 @@ func (f *bigIntField) Scan(src interface{}) (err error) {
case int64:
f.i = fftypes.NewFFBigInt(tv)
case uint:
if tv > math.MaxInt64 {
return i18n.NewError(context.Background(), i18n.MsgTypeRestoreFailed, src, f.i)
}
f.i = fftypes.NewFFBigInt(int64(tv))
case uint32:
f.i = fftypes.NewFFBigInt(int64(tv))
case uint64:
if tv > math.MaxInt64 {
return i18n.NewError(context.Background(), i18n.MsgTypeRestoreFailed, src, f.i)
}
f.i = fftypes.NewFFBigInt(int64(tv))
case fftypes.FFBigInt:
i := tv
Expand Down
4 changes: 2 additions & 2 deletions pkg/fftypes/int.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2022 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -45,7 +45,7 @@ func (i *FFuint64) UnmarshalJSON(b []byte) error {
if !ok {
return i18n.NewError(context.Background(), i18n.MsgBigIntParseFailed, b)
}
*i = FFuint64(bi.Int64())
*i = FFuint64(bi.Uint64())
return nil
case float64:
*i = FFuint64(val)
Expand Down
4 changes: 2 additions & 2 deletions pkg/fftypes/jsonobject.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ func (jd JSONObject) GetStringOk(key string) (string, bool) {
case int64:
return strconv.FormatInt(vt, 10), true
case uint:
return strconv.FormatInt(int64(vt), 10), true
return strconv.FormatUint(uint64(vt), 10), true
case uint8:
return strconv.FormatInt(int64(vt), 10), true
case uint16:
return strconv.FormatInt(int64(vt), 10), true
case uint32:
return strconv.FormatInt(int64(vt), 10), true
case uint64:
return strconv.FormatInt(int64(vt), 10), true
return strconv.FormatUint(vt, 10), true
case nil:
return "", false // no need to log for nil
default:
Expand Down
6 changes: 3 additions & 3 deletions pkg/fftypes/uuid.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -93,12 +93,12 @@ func (u *UUID) UnmarshalBinary(b []byte) error {
}

func (u *UUID) HashBucket(buckets int) int {
if u == nil {
if u == nil || buckets <= 0 {
return 0
}
// Take the last random 4 bytes and mod it against the bucket count to generate
// a deterministic hash bucket allocation for the UUID V4
return int(binary.BigEndian.Uint64((*u)[8:]) % uint64(buckets))
return int(binary.BigEndian.Uint16((*u)[8:])) % buckets

}

Expand Down
4 changes: 3 additions & 1 deletion pkg/fftypes/uuid_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2021 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -93,6 +93,8 @@ func TestHashBucket(t *testing.T) {
assert.Equal(t, 0, u3.HashBucket(2))

assert.Equal(t, 0, ((*UUID)(nil)).HashBucket(12345))
assert.Equal(t, 0, u3.HashBucket(-1))
assert.Equal(t, 0, u3.HashBucket(0))

}

Expand Down
4 changes: 2 additions & 2 deletions pkg/i18n/errors.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -82,7 +82,7 @@ func ffWrap(err error, msgKey ErrorMessageKey) error {

// NewError creates a new error
func NewError(ctx context.Context, msg ErrorMessageKey, inserts ...interface{}) error {
return ffWrap(errors.Errorf(truncate(ExpandWithCode(ctx, MessageKey(msg), inserts...), 2048)), msg)
return ffWrap(errors.New(truncate(ExpandWithCode(ctx, MessageKey(msg), inserts...), 2048)), msg)
}

// WrapError wraps an error
Expand Down
4 changes: 2 additions & 2 deletions pkg/metric/prometheusMetricsManager.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down Expand Up @@ -50,7 +50,7 @@ func checkAndUpdateLabelNames(ctx context.Context, labelNames []string, withDefa
for _, labelName := range labelNames {
if strings.HasPrefix(labelName, fireflySystemLabelsPrefix) {
err := i18n.NewError(ctx, i18n.MsgMetricsInvalidLabel, labelName, fireflySystemLabelsPrefix)
log.L(ctx).Errorf(err.Error())
log.L(ctx).Error(err.Error())
} else {
validLabelNames = append(validLabelNames, labelName)
}
Expand Down
17 changes: 15 additions & 2 deletions pkg/version/version_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
// Kaleido, Inc. CONFIDENTIAL
// Unpublished Copyright © 2023 Kaleido, Inc. All Rights Reserved.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package version

Expand Down
2 changes: 1 addition & 1 deletion pkg/wsclient/wsclient.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2023 Kaleido, Inc.
// Copyright © 2024 Kaleido, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down

0 comments on commit 1cf8bf2

Please sign in to comment.