Skip to content

Commit

Permalink
refactor: drop easyjson
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <[email protected]>
  • Loading branch information
knqyf263 committed Mar 1, 2024
1 parent a824e6b commit 1bede1e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3,065 deletions.
14 changes: 0 additions & 14 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,6 @@ func (Tool) Labeler() error {
return sh.Run("go", "install", "github.com/knqyf263/labeler@latest")
}

// EasyJSON installs easyjson
func (Tool) EasyJSON() error {
if exists(filepath.Join(GOBIN, "easyjson")) {
return nil
}
return sh.Run("go", "install", "github.com/mailru/easyjson/[email protected]")
}

// Kind installs kind cluster
func (Tool) Kind() error {
return sh.RunWithV(ENV, "go", "install", "sigs.k8s.io/[email protected]")
Expand Down Expand Up @@ -163,12 +155,6 @@ func Yacc() error {
return sh.Run("go", "generate", "./pkg/licensing/expression/...")
}

// Easyjson generates JSON marshaler/unmarshaler for TinyGo/WebAssembly as TinyGo doesn't support encoding/json.
func Easyjson() error {
mg.Deps(Tool{}.EasyJSON)
return sh.Run("easyjson", "./pkg/module/serialize/types.go")
}

type Test mg.Namespace

// FixtureContainerImages downloads and extracts required images
Expand Down
5 changes: 2 additions & 3 deletions pkg/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"regexp"
"sync"

"github.com/mailru/easyjson"
"github.com/samber/lo"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/api"
Expand Down Expand Up @@ -235,8 +234,8 @@ func unmarshal(mem api.Memory, ptrSize uint64, v any) error {
return nil
}

func marshal(ctx context.Context, m api.Module, malloc api.Function, v easyjson.Marshaler) (uint64, uint64, error) {
b, err := easyjson.Marshal(v)
func marshal(ctx context.Context, m api.Module, malloc api.Function, v any) (uint64, uint64, error) {
b, err := json.Marshal(v)
if err != nil {
return 0, 0, xerrors.Errorf("marshal error: %w", err)
}
Expand Down
10 changes: 0 additions & 10 deletions pkg/module/serialize/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,8 @@ import (
"github.com/aquasecurity/trivy/pkg/types"
)

// TinyGo doesn't support encoding/json, but github.com/mailru/easyjson for now.
// We need to generate JSON-related methods like MarshalEasyJSON implementing easyjson.Marshaler.
//
// $ make easyjson

//easyjson:json
type StringSlice []string

//easyjson:json
type AnalysisResult struct {
// TODO: support other fields as well
// OS *types.OS
Expand All @@ -34,7 +27,6 @@ type CustomResource struct {

type PostScanAction string

//easyjson:json
type PostScanSpec struct {
// What action the module will do in post scanning.
// value: INSERT, UPDATE and DELETE
Expand All @@ -45,8 +37,6 @@ type PostScanSpec struct {
IDs []string
}

//easyjson:json
type Results []Result

//easyjson:json
type Result types.Result
Loading

0 comments on commit 1bede1e

Please sign in to comment.