qntfy / kazaam

Arbitrary transformations of JSON in Golang
MIT License
283 stars 54 forks source link

Standard go Module resolution #111

Closed mariotoffia closed 3 years ago

mariotoffia commented 3 years ago

Is it possible to have a go.mod so I can include it using require in go.mod in my project?

Cheers, Mario

JoshuaC215 commented 3 years ago

Hey @mariotoffia, I'm not sure if this will cause issues since it doesn't include an update to use the semver major version on imports. Also looks like this needs to update the travis script, I suspect removing these two lines will fix or at least see if there are any other issues.

It will be at least a few days before I can take a closer look at this. Appreciate the pull request!

mariotoffia commented 3 years ago

@JoshKCarroll Thanks! I'm new to go so I've got it to work on my master branch.

It required that prepended /v3 on module name and all the imports is prepending /v3 as well, then the module resolver in my other project acknowledged it as a v3 module.

I understand if this is a issue and you don't wish to update it accordingly.

Have a look at my master branch (if you'd like) - I've created a specific branch for this PR so I would not interfere - since I need to update the module to my URL instead of yours (temporarily) while trying out.

Cheers, Mario :)

diff --git a/go.mod b/go.mod
index 37b8316..4ca7e8e 100644
--- a/go.mod
+++ b/go.mod
@@ -1,4 +1,4 @@
-module github.com/mariotoffia/kazaam
+module github.com/mariotoffia/kazaam/v3

 require (
        github.com/gofrs/uuid v4.0.0+incompatible`
diff --git a/kazaam.go b/kazaam.go
index 3240598..8e14b95 100644
--- a/kazaam.go
+++ b/kazaam.go
@@ -8,7 +8,7 @@ import (
        "fmt"
        "strings"

-       "github.com/mariotoffia/kazaam/transform"
+       "github.com/mariotoffia/kazaam/v3/transform"
        "github.com/qntfy/jsonparser"
 )

@@ -152,7 +152,7 @@ func New(specString string, config Config) (*Kazaam, error) {
 func (k *Kazaam) getTransform(s *spec) TransformFunc {
        // getting a non-existent transform is checked against before this function is
        // called, hence the _
-       tform, _ := k.config.transforms[*s.Operation]
+       tform := k.config.transforms[*s.Operation]
        return tform
 }
diff --git a/kazaam_benchmarks_test.go b/kazaam_benchmarks_test.go
index 14c67e9..6589546 100644
--- a/kazaam_benchmarks_test.go
+++ b/kazaam_benchmarks_test.go
@@ -3,7 +3,7 @@ package kazaam_test
 import (
        "testing"

-       "github.com/mariotoffia/kazaam"
+       "github.com/mariotoffia/kazaam/v3"
 )

 const (
diff --git a/kazaam_int_test.go b/kazaam_int_test.go
index 1e782d2..1788a8c 100644
--- a/kazaam_int_test.go
+++ b/kazaam_int_test.go
@@ -5,8 +5,8 @@ import (
        "reflect"
        "testing"

-       "github.com/mariotoffia/kazaam"
-       "github.com/mariotoffia/kazaam/transform"
+       "github.com/mariotoffia/kazaam/v3"
+       "github.com/mariotoffia/kazaam/v3/transform"
        "github.com/qntfy/jsonparser"
 )

@@ -370,13 +370,13 @@ func TestKazaamNoModify(t *testing.T) {
        }
 }

-func TestConfigdKazaamGet3rdPartyTransform(t *testing.T) {
+func TestConfigsKazaamGet3rdPartyTransform(t *testing.T) {
        kc := kazaam.NewDefaultConfig()
        kc.RegisterTransform("3rd-party", func(spec *transform.Config, data []byte) ([]byte, error) {
-               data, _ = jsonparser.Set(data, []byte(`"does-exist"`), "doesnt-exist")
+               data, _ = jsonparser.Set(data, []byte(`"does-exist"`), "doesn't-exist")
                return data, nil
        })
-       msgOut := `{"test":"data","doesnt-exist":"does-exist"}`
+       msgOut := `{"test":"data","doesn't-exist":"does-exist"}`

        k, _ := kazaam.New(`[{"operation": "3rd-party"}]`, kc)
        kazaamOut, _ := k.TransformJSONStringToString(`{"test":"data"}`)
diff --git a/kazaam_test.go b/kazaam_test.go
index 92f5993..4f9d47f 100644
--- a/kazaam_test.go
+++ b/kazaam_test.go
@@ -4,7 +4,7 @@ import (
        "fmt"
        "testing"

-       "github.com/mariotoffia/kazaam/transform"
+       "github.com/mariotoffia/kazaam/v3/transform"
        "github.com/qntfy/jsonparser"
 )
diff --git a/spec.go b/spec.go
index d4aa4f9..4e988b6 100644
--- a/spec.go
+++ b/spec.go
@@ -3,7 +3,7 @@ package kazaam
 import (
        "encoding/json"

-       "github.com/mariotoffia/kazaam/transform"
+       "github.com/mariotoffia/kazaam/v3/transform"
 )

 // Spec represents an individual spec element. It describes the name of the operation,
@@ -18,7 +18,7 @@ type spec struct {
 type specInt spec
 type specs []spec

-// UnmarshalJSON implements a custon unmarshaller for the Spec type
+// UnmarshalJSON implements a custom unmarshaler for the Spec type
 func (s *spec) UnmarshalJSON(b []byte) (err error) {
        j := specInt{}
        if err = json.Unmarshal(b, &j); err == nil {
JoshuaC215 commented 3 years ago

Hey @mariotoffia I merged https://github.com/qntfy/kazaam/pull/112 and bumped kazaam to v4.0.0 to support go mod with the semver import path. Let me know if you have any issues with use. I'm going to close this pull request. Thanks!