Skip to content

Commit

Permalink
Replace goccy/go-json as it panics sometimes (closes #217)
Browse files Browse the repository at this point in the history
  • Loading branch information
colmsnowplow committed Oct 10, 2022
1 parent be2dd83 commit 6da7734
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 162 deletions.
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/dlclark/regexp2 v1.7.0
github.com/dop251/goja v0.0.0-20220722151623-4765a9872229
github.com/goccy/go-json v0.9.10
github.com/hashicorp/hcl/v2 v2.13.0
github.com/json-iterator/go v1.1.12
github.com/snowplow/snowplow-golang-tracker/v2 v2.4.1
github.com/yuin/gluamapper v0.0.0-20150323120927-d836955830e7
github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64
Expand Down Expand Up @@ -91,7 +91,6 @@ require (
github.com/jcmturner/gokrb5/v8 v8.4.2 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3a
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/goccy/go-json v0.9.10 h1:hCeNmprSNLB8B8vQKWl6DpuH0t60oEs+TAk9a7CScKc=
github.com/goccy/go-json v0.9.10/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
github.com/golang-jwt/jwt v3.2.2+incompatible h1:IfV12K8xAKAnZqdXVzCZ+TOjboZ2keLg81eXfW3O+oY=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
Expand Down
4 changes: 4 additions & 0 deletions pkg/transform/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
package engine

import (
jsoniter "github.com/json-iterator/go"
"github.com/snowplow-devops/stream-replicator/pkg/transform"
)

// make a jsoniter instance that won't escape html
var json = jsoniter.Config{}.Froze()

// functionMaker is the interface that wraps the MakeFunction method
type functionMaker interface {
// MakeFunction returns a TransformationFunction that runs
Expand Down
3 changes: 1 addition & 2 deletions pkg/transform/engine/engine_javascript.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

goja "github.com/dop251/goja"
gojaparser "github.com/dop251/goja/parser"
gojson "github.com/goccy/go-json"
"github.com/mitchellh/mapstructure"

"github.com/snowplow-devops/stream-replicator/pkg/models"
Expand Down Expand Up @@ -153,7 +152,7 @@ func (e *JSEngine) MakeFunction(funcName string) transform.TransformationFunctio
message.Data = []byte(protoData)
case map[string]interface{}:
// encode
encoded, err := gojson.MarshalWithOption(protoData, gojson.DisableHTMLEscape())
encoded, err := json.Marshal(protoData)
if err != nil {
message.SetError(fmt.Errorf("error encoding message data"))
return nil, nil, message, nil
Expand Down
Loading

0 comments on commit 6da7734

Please sign in to comment.