Remove json.encode and json.decode functions
This commit is contained in:
parent
1d57a8814b
commit
dc48c16f1f
4 changed files with 0 additions and 90 deletions
|
@ -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},
|
||||
|
|
|
@ -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...)
|
||||
|
|
|
@ -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
|
||||
}
|
|
@ -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}`))
|
||||
})
|
||||
|
||||
}
|
Loading…
Reference in a new issue