Skip to content

Commit 37d955e

Browse files
committedDec 28, 2024·
refactor: replace utils.Marshal/Unmarshal with json.Marshal/json.Unmarshal
Signed-off-by: devhindo <lildevhind@gmail.com>
1 parent 5e7b75a commit 37d955e

File tree

6 files changed

+16
-14
lines changed

6 files changed

+16
-14
lines changed
 

‎.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
with:
2222
go-version: ${{ matrix.go-version }}
2323
- name: golangci-lint
24-
uses: golangci/golangci-lint-action@v3
24+
uses: golangci/golangci-lint-action@v6
2525
with:
2626
version: latest
2727
args: --timeout=5m

‎meshsync/exec.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"os"
2222
"strings"
2323
"time"
24+
"encoding/json"
2425

2526
"github.com/google/uuid"
2627
"github.com/layer5io/meshkit/broker"
@@ -46,7 +47,7 @@ func (h *Handler) processExecRequest(obj interface{}, cfg config.ListenerConfig)
4647
return err
4748
}
4849

49-
err = utils.Unmarshal(d, &reqs)
50+
err = json.Unmarshal([]byte(d), &reqs)
5051
if err != nil {
5152
return err
5253
}

‎meshsync/handlers.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package meshsync
33
import (
44
"fmt"
55
"time"
6+
"encoding/json"
67

78
"github.com/layer5io/meshkit/broker"
89
"github.com/layer5io/meshkit/utils"
@@ -98,14 +99,14 @@ func (h *Handler) ListenToRequests() {
9899

99100
// TODO: Add this to the broker pkg
100101
case "informer-store":
101-
d, err := utils.Marshal(request.Request.Payload)
102+
d, err := json.Marshal(request.Request.Payload)
102103
// TODO: Update broker pkg in Meshkit to include Reply types
103104
var payload struct{ Reply string }
104105
if err != nil {
105106
h.Log.Error(err)
106107
continue
107108
}
108-
err = utils.Unmarshal(d, &payload)
109+
err = json.Unmarshal(d, &payload)
109110
if err != nil {
110111
h.Log.Error(err)
111112
continue
@@ -188,13 +189,13 @@ func (h *Handler) WatchCRDs() {
188189
for event := range crdWatcher.ResultChan() {
189190

190191
crd := &kubernetes.CRDItem{}
191-
byt, err := utils.Marshal(event.Object)
192+
byt, err := json.Marshal(event.Object)
192193
if err != nil {
193194
h.Log.Error(err)
194195
continue
195196
}
196197

197-
err = utils.Unmarshal(byt, crd)
198+
err = json.Unmarshal(byt, crd)
198199
if err != nil {
199200
h.Log.Error(err)
200201
continue

‎meshsync/logstream.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ import (
44
"context"
55
"fmt"
66
"io"
7+
"encoding/json"
78

89
"github.com/layer5io/meshkit/broker"
9-
"github.com/layer5io/meshkit/utils"
1010
"github.com/layer5io/meshsync/internal/channels"
1111
"github.com/layer5io/meshsync/internal/config"
1212
"github.com/layer5io/meshsync/pkg/model"
@@ -15,12 +15,12 @@ import (
1515

1616
func (h *Handler) processLogRequest(obj interface{}, cfg config.ListenerConfig) error {
1717
reqs := make(model.LogRequests)
18-
d, err := utils.Marshal(obj)
18+
d, err := json.Marshal(obj)
1919
if err != nil {
2020
return err
2121
}
2222

23-
err = utils.Unmarshal(d, &reqs)
23+
err = json.Unmarshal(d, &reqs)
2424
if err != nil {
2525
return err
2626
}

‎pkg/model/model_converter.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ package model
22

33
import (
44
"encoding/base64"
5+
"encoding/json"
56
"fmt"
67

78
"github.com/buger/jsonparser"
89
"github.com/google/uuid"
910
"github.com/layer5io/meshkit/broker"
1011
"github.com/layer5io/meshkit/orchestration"
11-
"github.com/layer5io/meshkit/utils"
1212
iutils "github.com/layer5io/meshsync/pkg/utils"
1313
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1414
)
1515

1616
func ParseList(object unstructured.Unstructured, eventType broker.EventType) KubernetesResource {
1717
data, _ := object.MarshalJSON()
1818
result := KubernetesResource{}
19-
_ = utils.Unmarshal(string(data), &result)
19+
_ = json.Unmarshal(data, &result)
2020

2121
processorInstance := GetProcessorInstance(result.Kind)
2222
// ObjectMeta internal models

‎pkg/model/process.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import (
55
"fmt"
66
"net/url"
77
"strings"
8-
8+
"encoding/json"
9+
910
"github.com/layer5io/meshkit/broker"
10-
"github.com/layer5io/meshkit/utils"
1111
"github.com/layer5io/meshkit/utils/kubernetes"
1212
v1 "k8s.io/api/core/v1"
1313
)
@@ -21,7 +21,7 @@ func (s *K8SService) Process(data []byte, k8sresource *KubernetesResource, evtyp
2121

2222
k8sservice := &v1.Service{}
2323

24-
err := utils.Unmarshal(string(data), k8sservice)
24+
err := json.Unmarshal(data, k8sservice)
2525
if err != nil {
2626
return err
2727
}

0 commit comments

Comments
 (0)
Please sign in to comment.