From 37d955e1bb4942d797063970dec31a5f846cdde8 Mon Sep 17 00:00:00 2001 From: devhindo Date: Sat, 28 Dec 2024 17:33:53 +0200 Subject: [PATCH 1/2] refactor: replace utils.Marshal/Unmarshal with json.Marshal/json.Unmarshal Signed-off-by: devhindo --- .github/workflows/ci.yml | 2 +- meshsync/exec.go | 3 ++- meshsync/handlers.go | 9 +++++---- meshsync/logstream.go | 6 +++--- pkg/model/model_converter.go | 4 ++-- pkg/model/process.go | 6 +++--- 6 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6f273acc..e400fbcd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,7 +21,7 @@ jobs: with: go-version: ${{ matrix.go-version }} - name: golangci-lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 with: version: latest args: --timeout=5m diff --git a/meshsync/exec.go b/meshsync/exec.go index b71bfc30..8f0be156 100644 --- a/meshsync/exec.go +++ b/meshsync/exec.go @@ -21,6 +21,7 @@ import ( "os" "strings" "time" + "encoding/json" "github.com/google/uuid" "github.com/layer5io/meshkit/broker" @@ -46,7 +47,7 @@ func (h *Handler) processExecRequest(obj interface{}, cfg config.ListenerConfig) return err } - err = utils.Unmarshal(d, &reqs) + err = json.Unmarshal([]byte(d), &reqs) if err != nil { return err } diff --git a/meshsync/handlers.go b/meshsync/handlers.go index 5438ac77..fff3f30c 100644 --- a/meshsync/handlers.go +++ b/meshsync/handlers.go @@ -3,6 +3,7 @@ package meshsync import ( "fmt" "time" + "encoding/json" "github.com/layer5io/meshkit/broker" "github.com/layer5io/meshkit/utils" @@ -98,14 +99,14 @@ func (h *Handler) ListenToRequests() { // TODO: Add this to the broker pkg case "informer-store": - d, err := utils.Marshal(request.Request.Payload) + d, err := json.Marshal(request.Request.Payload) // TODO: Update broker pkg in Meshkit to include Reply types var payload struct{ Reply string } if err != nil { h.Log.Error(err) continue } - err = utils.Unmarshal(d, &payload) + err = json.Unmarshal(d, &payload) if err != nil { h.Log.Error(err) continue @@ -188,13 +189,13 @@ func (h *Handler) WatchCRDs() { for event := range crdWatcher.ResultChan() { crd := &kubernetes.CRDItem{} - byt, err := utils.Marshal(event.Object) + byt, err := json.Marshal(event.Object) if err != nil { h.Log.Error(err) continue } - err = utils.Unmarshal(byt, crd) + err = json.Unmarshal(byt, crd) if err != nil { h.Log.Error(err) continue diff --git a/meshsync/logstream.go b/meshsync/logstream.go index 26bdaa03..6db02908 100644 --- a/meshsync/logstream.go +++ b/meshsync/logstream.go @@ -4,9 +4,9 @@ import ( "context" "fmt" "io" + "encoding/json" "github.com/layer5io/meshkit/broker" - "github.com/layer5io/meshkit/utils" "github.com/layer5io/meshsync/internal/channels" "github.com/layer5io/meshsync/internal/config" "github.com/layer5io/meshsync/pkg/model" @@ -15,12 +15,12 @@ import ( func (h *Handler) processLogRequest(obj interface{}, cfg config.ListenerConfig) error { reqs := make(model.LogRequests) - d, err := utils.Marshal(obj) + d, err := json.Marshal(obj) if err != nil { return err } - err = utils.Unmarshal(d, &reqs) + err = json.Unmarshal(d, &reqs) if err != nil { return err } diff --git a/pkg/model/model_converter.go b/pkg/model/model_converter.go index 0d57fbdf..d084b465 100644 --- a/pkg/model/model_converter.go +++ b/pkg/model/model_converter.go @@ -2,13 +2,13 @@ package model import ( "encoding/base64" + "encoding/json" "fmt" "github.com/buger/jsonparser" "github.com/google/uuid" "github.com/layer5io/meshkit/broker" "github.com/layer5io/meshkit/orchestration" - "github.com/layer5io/meshkit/utils" iutils "github.com/layer5io/meshsync/pkg/utils" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) @@ -16,7 +16,7 @@ import ( func ParseList(object unstructured.Unstructured, eventType broker.EventType) KubernetesResource { data, _ := object.MarshalJSON() result := KubernetesResource{} - _ = utils.Unmarshal(string(data), &result) + _ = json.Unmarshal(data, &result) processorInstance := GetProcessorInstance(result.Kind) // ObjectMeta internal models diff --git a/pkg/model/process.go b/pkg/model/process.go index b1da7a7a..5f4b1978 100644 --- a/pkg/model/process.go +++ b/pkg/model/process.go @@ -5,9 +5,9 @@ import ( "fmt" "net/url" "strings" - + "encoding/json" + "github.com/layer5io/meshkit/broker" - "github.com/layer5io/meshkit/utils" "github.com/layer5io/meshkit/utils/kubernetes" v1 "k8s.io/api/core/v1" ) @@ -21,7 +21,7 @@ func (s *K8SService) Process(data []byte, k8sresource *KubernetesResource, evtyp k8sservice := &v1.Service{} - err := utils.Unmarshal(string(data), k8sservice) + err := json.Unmarshal(data, k8sservice) if err != nil { return err } From bf09d451a796e12e3e3c85b79c3088b247c9e362 Mon Sep 17 00:00:00 2001 From: devhindo Date: Sat, 28 Dec 2024 17:40:10 +0200 Subject: [PATCH 2/2] feat: add linting target to Makefile Signed-off-by: devhindo --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index fd397bdb..248d2e77 100644 --- a/Makefile +++ b/Makefile @@ -83,3 +83,6 @@ coverage: ## Runs unit tests test: check go test -failfast --short ./... -race +## Lint check Golang +lint: + golangci-lint run ./... \ No newline at end of file