Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

remove jmoiron/jsonq (#144)

Guilherme Oenning97c42affa75b
diff --git a/Gopkg.lock b/Gopkg.lock
index 4ad3415a5..56d6eb015 100644
--- a/Gopkg.lock
+++ b/Gopkg.lock
@@ -37,12 +37,6 @@
revision = "e9f42fa127660e552d0ad2b589868d403a9be7c6"
version = "v1.1.1"
-[[projects]]
- branch = "master"
- name = "github.com/jmoiron/jsonq"
- packages = ["."]
- revision = "e874b168d07ecc7808bc950a17998a8aa3141d82"
-
[[projects]]
name = "github.com/julienschmidt/httprouter"
packages = ["."]
@@ -106,6 +100,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
- inputs-digest = "73b06db72d4552f552bd4826e1c039c7f5798e375b38dcfe0623cab466a46d5f"
+ inputs-digest = "198beeaa534bac7c24eacfcfe544c93b2213b6e8e40fbf6b25332383eac38961"
solver-name = "gps-cdcl"
solver-version = 1
diff --git a/Gopkg.toml b/Gopkg.toml
index dcfebb3fc..464081d61 100644
--- a/Gopkg.toml
+++ b/Gopkg.toml
@@ -29,10 +29,6 @@
name = "github.com/gosimple/slug"
version = "1.0.3"
-[[constraint]]
- branch = "master"
- name = "github.com/jmoiron/jsonq"
-
[[constraint]]
name = "github.com/labstack/echo"
version = "=3.2.3"
diff --git a/app/handlers/signup_test.go b/app/handlers/signup_test.go
index 548ea48ea..8b0f531a2 100644
--- a/app/handlers/signup_test.go
+++ b/app/handlers/signup_test.go
@@ -67,8 +67,7 @@ func TestCheckAvailabilityHandler_ValidSubdomain(t *testing.T) {
code, response := server.WithParam("subdomain", "mycompany").ExecuteAsJSON(handlers.CheckAvailability())
Expect(code).To(Equal(200))
- _, err := response.String("message")
- Expect(err).NotTo(BeNil())
+ Expect(response.Contains("message")).To(BeFalse())
}
func TestCreateTenantHandler_EmptyInput(t *testing.T) {
@@ -122,8 +121,7 @@ func TestCreateTenantHandler_WithEmailAndName(t *testing.T) {
)
Expect(code).To(Equal(200))
- _, err := response.String("token")
- Expect(err).NotTo(BeNil())
+ Expect(response.Contains("token")).To(BeFalse())
tenant, err := services.Tenants.GetByDomain("mycompany")
diff --git a/app/pkg/jsonq/jsonq.go b/app/pkg/jsonq/jsonq.go
new file mode 100644
index 000000000..1518483a2
--- /dev/null
+++ b/app/pkg/jsonq/jsonq.go
@@ -0,0 +1,28 @@
+package jsonq
+
+import (
+ "encoding/json"
+)
+
+type Query struct {
+ m map[string]*json.RawMessage
+}
+
+func New(content string) *Query {
+ var m map[string]*json.RawMessage
+ err := json.Unmarshal([]byte(content), &m)
+ if err != nil {
+ panic(err)
+ }
+ return &Query{m: m}
+}
+
+func (q *Query) String(key string) (string, error) {
+ var str string
+ err := json.Unmarshal(*q.m[key], &str)
+ return str, err
+}
+
+func (q *Query) Contains(key string) bool {
+ return q.m[key] != nil
+}
diff --git a/app/pkg/jsonq/jsonq_test.go b/app/pkg/jsonq/jsonq_test.go
new file mode 100644
index 000000000..ed5f61b80
--- /dev/null
+++ b/app/pkg/jsonq/jsonq_test.go
@@ -0,0 +1,22 @@
+package jsonq_test
+
+import (
+ "testing"
+
+ "github.com/getfider/fider/app/pkg/jsonq"
+ . "github.com/onsi/gomega"
+)
+
+func TestGetString(t *testing.T) {
+ RegisterTestingT(t)
+
+ query := jsonq.New(`{ "name": "Jon Snow" }`)
+ Expect(query.String("name")).To(Equal("Jon Snow"))
+}
+
+func TestContains(t *testing.T) {
+ RegisterTestingT(t)
+
+ query := jsonq.New(`{ "name": "Jon Snow" }`)
+ Expect(query.Contains("what")).To(BeFalse())
+}
diff --git a/app/pkg/mock/server.go b/app/pkg/mock/server.go
index ec134366d..c8ae0a6b1 100644
--- a/app/pkg/mock/server.go
+++ b/app/pkg/mock/server.go
@@ -1,7 +1,6 @@
package mock
import (
- "encoding/json"
"fmt"
"io/ioutil"
"net/http"
@@ -12,8 +11,8 @@ import (
"github.com/getfider/fider/app"
"github.com/getfider/fider/app/middlewares"
"github.com/getfider/fider/app/models"
+ "github.com/getfider/fider/app/pkg/jsonq"
"github.com/getfider/fider/app/pkg/web"
- "github.com/jmoiron/jsonq"
)
// Server is a HTTP server wrapper for testing purpose
@@ -93,7 +92,7 @@ func (s *Server) Execute(handler web.HandlerFunc) (int, *httptest.ResponseRecord
}
// ExecuteAsJSON given handler and return json response
-func (s *Server) ExecuteAsJSON(handler web.HandlerFunc) (int, *jsonq.JsonQuery) {
+func (s *Server) ExecuteAsJSON(handler web.HandlerFunc) (int, *jsonq.Query) {
code, response := s.Execute(handler)
return code, toJSONQuery(response)
}
@@ -113,15 +112,15 @@ func (s *Server) ExecutePost(handler web.HandlerFunc, body string) (int, *httpte
}
// ExecutePostAsJSON executes given handler as POST and return json response
-func (s *Server) ExecutePostAsJSON(handler web.HandlerFunc, body string) (int, *jsonq.JsonQuery) {
+func (s *Server) ExecutePostAsJSON(handler web.HandlerFunc, body string) (int, *jsonq.Query) {
code, response := s.ExecutePost(handler, body)
return code, toJSONQuery(response)
}
-func toJSONQuery(response *httptest.ResponseRecorder) *jsonq.JsonQuery {
- var data interface{}
- decoder := json.NewDecoder(response.Body)
- decoder.Decode(&data)
- query := jsonq.NewQuery(data)
- return query
+func toJSONQuery(response *httptest.ResponseRecorder) *jsonq.Query {
+ b, err := ioutil.ReadAll(response.Body)
+ if err != nil {
+ panic(err)
+ }
+ return jsonq.New(string(b))
}
diff --git a/vendor/github.com/jmoiron/jsonq/.gitignore b/vendor/github.com/jmoiron/jsonq/.gitignore
deleted file mode 100644
index dbec55fb6..000000000
--- a/vendor/github.com/jmoiron/jsonq/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-*.sw[op]
diff --git a/vendor/github.com/jmoiron/jsonq/LICENSE b/vendor/github.com/jmoiron/jsonq/LICENSE
deleted file mode 100644
index 88b577e0d..000000000
--- a/vendor/github.com/jmoiron/jsonq/LICENSE
+++ /dev/null
@@ -1,23 +0,0 @@
- Copyright (c) 2012, Jason Moiron
-
- Permission is hereby granted, free of charge, to any person
- obtaining a copy of this software and associated documentation
- files (the "Software"), to deal in the Software without
- restriction, including without limitation the rights to use,
- copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the
- Software is furnished to do so, subject to the following
- conditions:
-
- The above copyright notice and this permission notice shall be
- included in all copies or substantial portions of the Software.
-
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- OTHER DEALINGS IN THE SOFTWARE.
-
diff --git a/vendor/github.com/jmoiron/jsonq/README.md b/vendor/github.com/jmoiron/jsonq/README.md
deleted file mode 100644
index 4fba5edb2..000000000
--- a/vendor/github.com/jmoiron/jsonq/README.md
+++ /dev/null
@@ -1,83 +0,0 @@
-# jsonq
-
-[![Build Status](https://drone.io/github.com/jmoiron/jsonq/status.png)](https://drone.io/github.com/jmoiron/jsonq/latest) [![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/jmoiron/jsonq) [![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://raw.githubusercontent.com/jmoiron/jsonq/master/LICENSE)
-
-
-Simplify your golang json usage by extracting fields or items from arrays and objects with a simple, hierarchical query. [API Documentation](http://godoc.org/github.com/jmoiron/jsonq) on godoc.org.
-
-This package is meant to make working with complex feeds a bit more easy. If you have simple feeds you want to model with struct types, check out [jflect](http://github.com/str1ngs/jflect), which will create struct definitions given a json document.
-
-# installing
-
-```
-go get github.com/jmoiron/jsonq
-```
-
-# usage
-
-Given some json data like:
-
-```javascript
-{
- "foo": 1,
- "bar": 2,
- "test": "Hello, world!",
- "baz": 123.1,
- "array": [
- {"foo": 1},
- {"bar": 2},
- {"baz": 3}
- ],
- "subobj": {
- "foo": 1,
- "subarray": [1,2,3],
- "subsubobj": {
- "bar": 2,
- "baz": 3,
- "array": ["hello", "world"]
- }
- },
- "bool": true
-}
-```
-
-Decode it into a `map[string]interface{}`:
-
-```go
-import (
- "strings"
- "encoding/json"
- "github.com/jmoiron/jsonq"
-)
-
-data := map[string]interface{}{}
-dec := json.NewDecoder(strings.NewReader(jsonstring))
-dec.Decode(&data)
-jq := jsonq.NewQuery(data)
-```
-
-From here, you can query along different keys and indexes:
-
-```go
-// data["foo"] -> 1
-jq.Int("foo")
-
-// data["subobj"]["subarray"][1] -> 2
-jq.Int("subobj", "subarray", "1")
-
-// data["subobj"]["subarray"]["array"][0] -> "hello"
-jq.String("subobj", "subsubobj", "array", "0")
-
-// data["subobj"] -> map[string]interface{}{"subobj": ...}
-obj, err := jq.Object("subobj")
-```
-
-Missing keys, out of bounds indexes, and type failures will return errors.
-For simplicity, integer keys (ie, {"0": "zero"}) are inaccessible
-by `jsonq` as integer strings are assumed to be array indexes.
-
-The `Int` and `Float` methods will attempt to parse numbers from string
-values to ease the use of many real world feeds which deliver numbers as strings.
-
-Suggestions/comments please tweet [@jmoiron](http://twitter.com/jmoiron)
-
diff --git a/vendor/github.com/jmoiron/jsonq/autotest.sh b/vendor/github.com/jmoiron/jsonq/autotest.sh
deleted file mode 100755
index b154ad37d..000000000
--- a/vendor/github.com/jmoiron/jsonq/autotest.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/bash
-
-cur=`pwd`
-
-inotifywait -mqr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' \
- -e modify ./ | while read date time dir file; do
- ext="${file##*.}"
- if [[ "$ext" = "go" ]]; then
- echo "$file changed @ $time $date, rebuilding..."
- go test
- fi
-done
-
diff --git a/vendor/github.com/jmoiron/jsonq/doc.go b/vendor/github.com/jmoiron/jsonq/doc.go
deleted file mode 100644
index ac030102f..000000000
--- a/vendor/github.com/jmoiron/jsonq/doc.go
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
-Package jsonq simplify your json usage with a simple hierarchical query.
-
-Given some json data like:
-
- {
- "foo": 1,
- "bar": 2,
- "test": "Hello, world!",
- "baz": 123.1,
- "array": [
- {"foo": 1},
- {"bar": 2},
- {"baz": 3}
- ],
- "subobj": {
- "foo": 1,
- "subarray": [1,2,3],
- "subsubobj": {
- "bar": 2,
- "baz": 3,
- "array": ["hello", "world"]
- }
- },
- "bool": true
- }
-
-Decode it into a map[string]interrface{}:
-
- import (
- "strings"
- "encoding/json"
- "github.com/jmoiron/jsonq"
- )
-
- data := map[string]interface{}{}
- dec := json.NewDecoder(strings.NewReader(jsonstring))
- dec.Decode(&data)
- jq := jsonq.NewQuery(data)
-
-From here, you can query along different keys and indexes:
-
- // data["foo"] -> 1
- jq.Int("foo")
-
- // data["subobj"]["subarray"][1] -> 2
- jq.Int("subobj", "subarray", "1")
-
- // data["subobj"]["subarray"]["array"][0] -> "hello"
- jq.String("subobj", "subsubobj", "array", "0")
-
- // data["subobj"] -> map[string]interface{}{"subobj": ...}
- obj, err := jq.Object("subobj")
-
- Notes:
-
-Missing keys, out of bounds indexes, and type failures will return errors.
-For simplicity, integer keys (ie, {"0": "zero"}) are inaccessible by `jsonq`
-as integer strings are assumed to be array indexes.
-
-*/
-package jsonq
diff --git a/vendor/github.com/jmoiron/jsonq/jsonq.go b/vendor/github.com/jmoiron/jsonq/jsonq.go
deleted file mode 100644
index 5b3e2b37e..000000000
--- a/vendor/github.com/jmoiron/jsonq/jsonq.go
+++ /dev/null
@@ -1,304 +0,0 @@
-package jsonq
-
-import (
- "fmt"
- "strconv"
-)
-
-// JsonQuery is an object that enables querying of a Go map with a simple
-// positional query language.
-type JsonQuery struct {
- blob map[string]interface{}
-}
-
-// stringFromInterface converts an interface{} to a string and returns an error if types don't match.
-func stringFromInterface(val interface{}) (string, error) {
- switch val.(type) {
- case string:
- return val.(string), nil
- }
- return "", fmt.Errorf("Expected string value for String, got \"%v\"\n", val)
-}
-
-// boolFromInterface converts an interface{} to a bool and returns an error if types don't match.
-func boolFromInterface(val interface{}) (bool, error) {
- switch val.(type) {
- case bool:
- return val.(bool), nil
- }
- return false, fmt.Errorf("Expected boolean value for Bool, got \"%v\"\n", val)
-}
-
-// floatFromInterface converts an interface{} to a float64 and returns an error if types don't match.
-func floatFromInterface(val interface{}) (float64, error) {
- switch val.(type) {
- case float64:
- return val.(float64), nil
- case int:
- return float64(val.(int)), nil
- case string:
- fval, err := strconv.ParseFloat(val.(string), 64)
- if err == nil {
- return fval, nil
- }
- }
- return 0.0, fmt.Errorf("Expected numeric value for Float, got \"%v\"\n", val)
-}
-
-// intFromInterface converts an interface{} to an int and returns an error if types don't match.
-func intFromInterface(val interface{}) (int, error) {
- switch val.(type) {
- case float64:
- return int(val.(float64)), nil
- case string:
- ival, err := strconv.ParseFloat(val.(string), 64)
- if err == nil {
- return int(ival), nil
- }
- case int:
- return val.(int), nil
- }
- return 0, fmt.Errorf("Expected numeric value for Int, got \"%v\"\n", val)
-}
-
-// objectFromInterface converts an interface{} to a map[string]interface{} and returns an error if types don't match.
-func objectFromInterface(val interface{}) (map[string]interface{}, error) {
- switch val.(type) {
- case map[string]interface{}:
- return val.(map[string]interface{}), nil
- }
- return map[string]interface{}{}, fmt.Errorf("Expected json object for Object, got \"%v\"\n", val)
-}
-
-// arrayFromInterface converts an interface{} to an []interface{} and returns an error if types don't match.
-func arrayFromInterface(val interface{}) ([]interface{}, error) {
- switch val.(type) {
- case []interface{}:
- return val.([]interface{}), nil
- }
- return []interface{}{}, fmt.Errorf("Expected json array for Array, got \"%v\"\n", val)
-}
-
-// NewQuery creates a new JsonQuery obj from an interface{}.
-func NewQuery(data interface{}) *JsonQuery {
- j := new(JsonQuery)
- j.blob = data.(map[string]interface{})
- return j
-}
-
-// Bool extracts a bool the JsonQuery
-func (j *JsonQuery) Bool(s ...string) (bool, error) {
- val, err := rquery(j.blob, s...)
- if err != nil {
- return false, err
- }
- return boolFromInterface(val)
-}
-
-// Float extracts a float from the JsonQuery
-func (j *JsonQuery) Float(s ...string) (float64, error) {
- val, err := rquery(j.blob, s...)
- if err != nil {
- return 0.0, err
- }
- return floatFromInterface(val)
-}
-
-// Int extracts an int from the JsonQuery
-func (j *JsonQuery) Int(s ...string) (int, error) {
- val, err := rquery(j.blob, s...)
- if err != nil {
- return 0, err
- }
- return intFromInterface(val)
-}
-
-// String extracts a string from the JsonQuery
-func (j *JsonQuery) String(s ...string) (string, error) {
- val, err := rquery(j.blob, s...)
- if err != nil {
- return "", err
- }
- return stringFromInterface(val)
-}
-
-// Object extracts a json object from the JsonQuery
-func (j *JsonQuery) Object(s ...string) (map[string]interface{}, error) {
- val, err := rquery(j.blob, s...)
- if err != nil {
- return map[string]interface{}{}, err
- }
- return objectFromInterface(val)
-}
-
-// Array extracts a []interface{} from the JsonQuery
-func (j *JsonQuery) Array(s ...string) ([]interface{}, error) {
- val, err := rquery(j.blob, s...)
- if err != nil {
- return []interface{}{}, err
- }
- return arrayFromInterface(val)
-}
-
-// Interface extracts an interface{} from the JsonQuery
-func (j *JsonQuery) Interface(s ...string) (interface{}, error) {
- val, err := rquery(j.blob, s...)
- if err != nil {
- return nil, err
- }
- return val, nil
-}
-
-// ArrayOfStrings extracts an array of strings from some json
-func (j *JsonQuery) ArrayOfStrings(s ...string) ([]string, error) {
- array, err := j.Array(s...)
- if err != nil {
- return []string{}, err
- }
- toReturn := make([]string, len(array))
- for index, val := range array {
- toReturn[index], err = stringFromInterface(val)
- if err != nil {
- return toReturn, err
- }
- }
- return toReturn, nil
-}
-
-// ArrayOfInts extracts an array of ints from some json
-func (j *JsonQuery) ArrayOfInts(s ...string) ([]int, error) {
- array, err := j.Array(s...)
- if err != nil {
- return []int{}, err
- }
- toReturn := make([]int, len(array))
- for index, val := range array {
- toReturn[index], err = intFromInterface(val)
- if err != nil {
- return toReturn, err
- }
- }
- return toReturn, nil
-}
-
-// ArrayOfFloats extracts an array of float64s from some json
-func (j *JsonQuery) ArrayOfFloats(s ...string) ([]float64, error) {
- array, err := j.Array(s...)
- if err != nil {
- return []float64{}, err
- }
- toReturn := make([]float64, len(array))
- for index, val := range array {
- toReturn[index], err = floatFromInterface(val)
- if err != nil {
- return toReturn, err
- }
- }
- return toReturn, nil
-}
-
-// ArrayOfBools extracts an array of bools from some json
-func (j *JsonQuery) ArrayOfBools(s ...string) ([]bool, error) {
- array, err := j.Array(s...)
- if err != nil {
- return []bool{}, err
- }
- toReturn := make([]bool, len(array))
- for index, val := range array {
- toReturn[index], err = boolFromInterface(val)
- if err != nil {
- return toReturn, err
- }
- }
- return toReturn, nil
-}
-
-// ArrayOfObjects extracts an array of map[string]interface{} (objects) from some json
-func (j *JsonQuery) ArrayOfObjects(s ...string) ([]map[string]interface{}, error) {
- array, err := j.Array(s...)
- if err != nil {
- return []map[string]interface{}{}, err
- }
- toReturn := make([]map[string]interface{}, len(array))
- for index, val := range array {
- toReturn[index], err = objectFromInterface(val)
- if err != nil {
- return toReturn, err
- }
- }
- return toReturn, nil
-}
-
-// ArrayOfArrays extracts an array of []interface{} (arrays) from some json
-func (j *JsonQuery) ArrayOfArrays(s ...string) ([][]interface{}, error) {
- array, err := j.Array(s...)
- if err != nil {
- return [][]interface{}{}, err
- }
- toReturn := make([][]interface{}, len(array))
- for index, val := range array {
- toReturn[index], err = arrayFromInterface(val)
- if err != nil {
- return toReturn, err
- }
- }
- return toReturn, nil
-}
-
-// Matrix2D is an alias for ArrayOfArrays
-func (j *JsonQuery) Matrix2D(s ...string) ([][]interface{}, error) {
- return j.ArrayOfArrays(s...)
-}
-
-// Recursively query a decoded json blob
-func rquery(blob interface{}, s ...string) (interface{}, error) {
- var (
- val interface{}
- err error
- )
- val = blob
- for _, q := range s {
- val, err = query(val, q)
- if err != nil {
- return nil, err
- }
- }
- switch val.(type) {
- case nil:
- return nil, fmt.Errorf("Nil value found at %s\n", s[len(s)-1])
- }
- return val, nil
-}
-
-// query a json blob for a single field or index. If query is a string, then
-// the blob is treated as a json object (map[string]interface{}). If query is
-// an integer, the blob is treated as a json array ([]interface{}). Any kind
-// of key or index error will result in a nil return value with an error set.
-func query(blob interface{}, query string) (interface{}, error) {
- index, err := strconv.Atoi(query)
- // if it's an integer, then we treat the current interface as an array
- if err == nil {
- switch blob.(type) {
- case []interface{}:
- default:
- return nil, fmt.Errorf("Array index on non-array %v\n", blob)
- }
- if len(blob.([]interface{})) > index {
- return blob.([]interface{})[index], nil
- }
- return nil, fmt.Errorf("Array index %d on array %v out of bounds\n", index, blob)
- }
-
- // blob is likely an object, but verify first
- switch blob.(type) {
- case map[string]interface{}:
- default:
- return nil, fmt.Errorf("Object lookup \"%s\" on non-object %v\n", query, blob)
- }
-
- val, ok := blob.(map[string]interface{})[query]
- if !ok {
- return nil, fmt.Errorf("Object %v does not contain field %s\n", blob, query)
- }
- return val, nil
-}
diff --git a/vendor/github.com/jmoiron/jsonq/jsonq_test.go b/vendor/github.com/jmoiron/jsonq/jsonq_test.go
deleted file mode 100644
index 9b1835bda..000000000
--- a/vendor/github.com/jmoiron/jsonq/jsonq_test.go
+++ /dev/null
@@ -1,186 +0,0 @@
-package jsonq
-
-import (
- "encoding/json"
- "fmt"
- "strings"
- "testing"
-)
-
-const TestData = `{
- "foo": 1,
- "bar": 2,
- "test": "Hello, world!",
- "baz": 123.1,
- "numstring": "42",
- "floatstring": "42.1",
- "array": [
- {"foo": 1},
- {"bar": 2},
- {"baz": 3}
- ],
- "subobj": {
- "foo": 1,
- "subarray": [1,2,3],
- "subsubobj": {
- "bar": 2,
- "baz": 3,
- "array": ["hello", "world"]
- }
- },
- "collections": {
- "bools": [false, true, false],
- "strings": ["hello", "strings"],
- "numbers": [1,2,3,4],
- "arrays": [[1.0,2.0],[2.0,3.0],[4.0,3.0]],
- "objects": [
- {"obj1": 1},
- {"obj2": 2}
- ]
- },
- "bool": true
-}`
-
-func tErr(t *testing.T, err error) {
- if err != nil {
- t.Errorf("Error: %v\n", err)
- }
-}
-
-func TestQuery(t *testing.T) {
- data := map[string]interface{}{}
- dec := json.NewDecoder(strings.NewReader(TestData))
- err := dec.Decode(&data)
- tErr(t, err)
- q := NewQuery(data)
-
- ival, err := q.Int("foo")
- if ival != 1 {
- t.Errorf("Expecting 1, got %v\n", ival)
- }
- tErr(t, err)
- ival, err = q.Int("bar")
- if ival != 2 {
- t.Errorf("Expecting 2, got %v\n", ival)
- }
- tErr(t, err)
-
- ival, err = q.Int("subobj", "foo")
- if ival != 1 {
- t.Errorf("Expecting 1, got %v\n", ival)
- }
- tErr(t, err)
-
- // test that strings can get int-ed
- ival, err = q.Int("numstring")
- if ival != 42 {
- t.Errorf("Expecting 42, got %v\n", ival)
- }
- tErr(t, err)
-
- for i := 0; i < 3; i++ {
- ival, err := q.Int("subobj", "subarray", fmt.Sprintf("%d", i))
- if ival != i+1 {
- t.Errorf("Expecting %d, got %v\n", i+1, ival)
- }
- tErr(t, err)
- }
-
- fval, err := q.Float("baz")
- if fval != 123.1 {
- t.Errorf("Expecting 123.1, got %f\n", fval)
- }
- tErr(t, err)
-
- // test that strings can get float-ed
- fval, err = q.Float("floatstring")
- if fval != 42.1 {
- t.Errorf("Expecting 42.1, got %v\n", fval)
- }
- tErr(t, err)
-
- sval, err := q.String("test")
- if sval != "Hello, world!" {
- t.Errorf("Expecting \"Hello, World!\", got \"%v\"\n", sval)
- }
-
- sval, err = q.String("subobj", "subsubobj", "array", "0")
- if sval != "hello" {
- t.Errorf("Expecting \"hello\", got \"%s\"\n", sval)
- }
- tErr(t, err)
-
- bval, err := q.Bool("bool")
- if !bval {
- t.Errorf("Expecting true, got %v\n", bval)
- }
- tErr(t, err)
-
- obj, err := q.Object("subobj", "subsubobj")
- tErr(t, err)
- q2 := NewQuery(obj)
- sval, err = q2.String("array", "1")
- if sval != "world" {
- t.Errorf("Expecting \"world\", got \"%s\"\n", sval)
- }
- tErr(t, err)
-
- aobj, err := q.Array("subobj", "subarray")
- tErr(t, err)
- if aobj[0].(float64) != 1 {
- t.Errorf("Expecting 1, got %v\n", aobj[0])
- }
-
- iobj, err := q.Interface("numstring")
- tErr(t, err)
- if _, ok := iobj.(string); !ok {
- t.Errorf("Expecting type string got: %s", iobj)
- }
-
- /*
- Test Extraction of typed slices
- */
-
- //test array of strings
- astrings, err := q.ArrayOfStrings("collections", "strings")
- tErr(t, err)
- if astrings[0] != "hello" {
- t.Errorf("Expecting hello, got %v\n", astrings[0])
- }
-
- //test array of ints
- aints, err := q.ArrayOfInts("collections", "numbers")
- tErr(t, err)
- if aints[0] != 1 {
- t.Errorf("Expecting 1, got %v\n", aints[0])
- }
-
- //test array of floats
- afloats, err := q.ArrayOfFloats("collections", "numbers")
- tErr(t, err)
- if afloats[0] != 1.0 {
- t.Errorf("Expecting 1.0, got %v\n", afloats[0])
- }
-
- //test array of bools
- abools, err := q.ArrayOfBools("collections", "bools")
- tErr(t, err)
- if abools[0] {
- t.Errorf("Expecting true, got %v\n", abools[0])
- }
-
- //test array of arrays
- aa, err := q.ArrayOfArrays("collections", "arrays")
- tErr(t, err)
- if aa[0][0].(float64) != 1 {
- t.Errorf("Expecting 1, got %v\n", aa[0][0])
- }
-
- //test array of objs
- aobjs, err := q.ArrayOfObjects("collections", "objects")
- tErr(t, err)
- if aobjs[0]["obj1"].(float64) != 1 {
- t.Errorf("Expecting 1, got %v\n", aobjs[0]["obj1"])
- }
-
-}
diff --git a/views/base.html b/views/base.html
index da6e93e07..15ab0aaf5 100644
--- a/views/base.html
+++ b/views/base.html
@@ -4,7 +4,7 @@
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<link rel="icon" type="image/x-icon" href="/favicon.ico">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.css" integrity="sha256-/Z28yXtfBv/6/alw+yZuODgTbKZm86IKbPE/5kjO/xY=" crossorigin="anonymous" />
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.css" />
<link rel="stylesheet" href="/assets/css/{{ .__StyleBundle }}" />
<title>{{ template "title" .}}</title>
<meta property="og:title" content="{{template "title" .}}" />
@@ -30,8 +30,8 @@
{{ end }}
{{template "content" .}}
<script src="https://cdn.polyfill.io/v2/polyfill.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.js" integrity="sha256-Bhi6GMQ/72uYZcJXCJ2LToOIcN3+Cx47AZnq/Bw1f7A=" crossorigin="anonymous"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.13/semantic.min.js"></script>
<script src="/assets/js/{{ .__JavaScriptBundle }}"></script>
<script type="text/javascript">
{{template "javascript" .}}