From dc48c16f1f2a73fa491d4c37ca2890e6eea07d6c Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Mon, 17 Feb 2020 13:36:04 +0000 Subject: [PATCH] Remove json.encode and json.decode functions --- sql/funcs.go | 4 ---- util/fncs/fnc.go | 6 ------ util/fncs/json.go | 32 ---------------------------- util/fncs/json_test.go | 48 ------------------------------------------ 4 files changed, 90 deletions(-) delete mode 100644 util/fncs/json.go delete mode 100644 util/fncs/json_test.go diff --git a/sql/funcs.go b/sql/funcs.go index 5caffbf9..caa0b41c 100644 --- a/sql/funcs.go +++ b/sql/funcs.go @@ -93,10 +93,6 @@ var funcs = map[string]map[int]interface{}{ "purge.if": {2: nil}, "purge.not": {2: nil}, - // Json implementation - "json.decode": {1: nil}, - "json.encode": {1: nil}, - // Geo implementation "geo.point": {1: nil, 2: nil}, "geo.circle": {2: nil}, diff --git a/util/fncs/fnc.go b/util/fncs/fnc.go index 5c049bd0..4985af34 100644 --- a/util/fncs/fnc.go +++ b/util/fncs/fnc.go @@ -63,12 +63,6 @@ func Run(ctx context.Context, name string, args ...interface{}) (interface{}, er case "purge.not": return purgeNot(ctx, args...) - // Json implementation - case "json.decode": - return jsonDecode(ctx, args...) - case "json.encode": - return jsonEncode(ctx, args...) - // Geo implementation case "geo.point": return geoPoint(ctx, args...) diff --git a/util/fncs/json.go b/util/fncs/json.go deleted file mode 100644 index 37d93214..00000000 --- a/util/fncs/json.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright © 2016 Abcum Ltd -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fncs - -import ( - "context" - - "encoding/json" -) - -func jsonDecode(ctx context.Context, args ...interface{}) (out interface{}, err error) { - bit, _ := ensureBytes(args[0]) - json.Unmarshal(bit, &out) - return -} - -func jsonEncode(ctx context.Context, args ...interface{}) (interface{}, error) { - bit, _ := json.Marshal(args[0]) - return bit, nil -} diff --git a/util/fncs/json_test.go b/util/fncs/json_test.go deleted file mode 100644 index 568f5e7b..00000000 --- a/util/fncs/json_test.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright © 2016 Abcum Ltd -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package fncs - -import ( - "context" - "testing" - - . "github.com/smartystreets/goconvey/convey" -) - -func TestJson(t *testing.T) { - - var res interface{} - - Convey("json.decode(a) works properly", t, func() { - res, _ = Run(context.Background(), "json.decode", "true") - So(res, ShouldResemble, true) - res, _ = Run(context.Background(), "json.decode", "13579") - So(res, ShouldResemble, float64(13579)) - res, _ = Run(context.Background(), "json.decode", `{"test":true}`) - So(res, ShouldResemble, map[string]interface{}{ - "test": true, - }) - }) - - Convey("json.encode(a) works properly", t, func() { - res, _ = Run(context.Background(), "json.encode", true) - So(res, ShouldResemble, []byte("true")) - res, _ = Run(context.Background(), "json.encode", 13579) - So(res, ShouldResemble, []byte("13579")) - res, _ = Run(context.Background(), "json.encode", map[string]interface{}{"test": true}) - So(res, ShouldResemble, []byte(`{"test":true}`)) - }) - -}