Skip to content

Commit 2a0ef1c

Browse files
committed
feat: modernize to match go 1.26 and remove unused functions
1 parent 177b852 commit 2a0ef1c

17 files changed

Lines changed: 122 additions & 524 deletions

File tree

net/http/response.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func ByteArrayResponse(w http.ResponseWriter, r *http.Request, contentType strin
170170
}
171171

172172
// JSONResponse Marshals response with header
173-
func JSONResponse(w http.ResponseWriter, r *http.Request, result interface{}) error {
173+
func JSONResponse(w http.ResponseWriter, r *http.Request, result any) error {
174174
body, err := json.Marshal(result)
175175
if err != nil {
176176
return ErrorResponse(w, r, err)

pkg/gorm/zerolog_logger.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ func (l Logger) LogMode(logger.LogLevel) logger.Interface {
2121
return l
2222
}
2323

24-
func (l Logger) Error(ctx context.Context, msg string, opts ...interface{}) {
24+
func (l Logger) Error(ctx context.Context, msg string, opts ...any) {
2525
zerolog.Ctx(ctx).Error().Msgf(msg, opts...)
2626
}
2727

28-
func (l Logger) Warn(ctx context.Context, msg string, opts ...interface{}) {
28+
func (l Logger) Warn(ctx context.Context, msg string, opts ...any) {
2929
zerolog.Ctx(ctx).Warn().Msgf(msg, opts...)
3030
}
3131

32-
func (l Logger) Info(ctx context.Context, msg string, opts ...interface{}) {
32+
func (l Logger) Info(ctx context.Context, msg string, opts ...any) {
3333
zerolog.Ctx(ctx).Info().Msgf(msg, opts...)
3434
}
3535

utils/bools.go

Lines changed: 0 additions & 6 deletions
This file was deleted.

utils/json/json.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var lock sync.Mutex
1313
// Marshal is a function that marshals the object into an
1414
// io.Reader.
1515
// By default, it uses the JSON marshaller.
16-
var Marshal = func(v interface{}) (io.Reader, error) {
16+
var Marshal = func(v any) (io.Reader, error) {
1717
b, err := json.MarshalIndent(v, "", "\t")
1818
if err != nil {
1919
return nil, err
@@ -22,7 +22,7 @@ var Marshal = func(v interface{}) (io.Reader, error) {
2222
}
2323

2424
// Save saves a representation of v to the file at path.
25-
func Save(path string, v interface{}) error {
25+
func Save(path string, v any) error {
2626
lock.Lock()
2727
defer lock.Unlock()
2828
f, err := os.Create(path)
@@ -40,7 +40,7 @@ func Save(path string, v interface{}) error {
4040
return err
4141
}
4242

43-
func Load(path string, v interface{}) error {
43+
func Load(path string, v any) error {
4444
lock.Lock()
4545
defer lock.Unlock()
4646
f, err := os.Open(path)
@@ -56,12 +56,12 @@ func Load(path string, v interface{}) error {
5656
// Unmarshal is a function that unmarshals the data from the
5757
// reader into the specified value.
5858
// By default, it uses the JSON unmarshaller.
59-
var Unmarshal = func(r io.Reader, v interface{}) error {
59+
var Unmarshal = func(r io.Reader, v any) error {
6060
return json.NewDecoder(r).Decode(v)
6161
}
6262

6363
// Pretty Gets json from data
64-
func Pretty(data interface{}) (*string, error) {
64+
func Pretty(data any) (*string, error) {
6565
b, err := json.Marshal(data)
6666
if err != nil {
6767
return nil, err

utils/maps/utils.go

Lines changed: 0 additions & 79 deletions
This file was deleted.

utils/maps/utils_test.go

Lines changed: 0 additions & 142 deletions
This file was deleted.

utils/mergo/transformers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (ct CombinedTransformer) Transformer(typ reflect.Type) func(dst, src reflec
2727
type BoolPtrTransformer struct{}
2828

2929
func (t BoolPtrTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Value) error {
30-
if typ == reflect.TypeOf(new(bool)) {
30+
if typ == reflect.TypeFor[*bool]() {
3131
return func(dst, src reflect.Value) error {
3232
if !src.IsNil() && dst.CanSet() {
3333
dst.Set(src)
@@ -43,7 +43,7 @@ type ResourceQuantityTransformer struct {
4343
}
4444

4545
func (t ResourceQuantityTransformer) Transformer(typ reflect.Type) func(dst, src reflect.Value) error {
46-
if typ == reflect.TypeOf(resource.Quantity{}) {
46+
if typ == reflect.TypeFor[resource.Quantity]() {
4747
return func(dst, src reflect.Value) error {
4848
if dst.CanSet() {
4949
srcVal := (src.Interface()).(resource.Quantity)

utils/numbers/number_utils.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

utils/pointers/pointer_utils.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package pointers
22

3-
// Ptr Helper function to get the pointer of an instance
4-
func Ptr[T any](i T) *T {
5-
return &i
6-
}
7-
83
func Val[T any](i *T) T {
94
var value T
105
if i != nil {

utils/pointers/pointer_utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func TestPointers(t *testing.T) {
10-
var p = Ptr(1337)
10+
var p = new(1337)
1111
v := Val(p)
1212

1313
assert.Equal(t, 1337, v)

0 commit comments

Comments
 (0)