mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-18 21:37:56 +08:00
scaffold for volume server query feature
This commit is contained in:
5
weed/query/json/query_json.go
Normal file
5
weed/query/json/query_json.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package json
|
||||
|
||||
func QueryJson(jsonLine string, query string) (jsonOutput string) {
|
||||
return jsonLine
|
||||
}
|
73
weed/query/json/query_json_test.go
Normal file
73
weed/query/json/query_json_test.go
Normal file
@@ -0,0 +1,73 @@
|
||||
package json
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func TestGjson(t *testing.T) {
|
||||
data := `
|
||||
{
|
||||
"quiz": {
|
||||
"sport": {
|
||||
"q1": {
|
||||
"question": "Which one is correct team name in NBA?",
|
||||
"options": [
|
||||
"New York Bulls",
|
||||
"Los Angeles Kings",
|
||||
"Golden State Warriros",
|
||||
"Huston Rocket"
|
||||
],
|
||||
"answer": "Huston Rocket"
|
||||
}
|
||||
},
|
||||
"maths": {
|
||||
"q1": {
|
||||
"question": "5 + 7 = ?",
|
||||
"options": [
|
||||
"10",
|
||||
"11",
|
||||
"12",
|
||||
"13"
|
||||
],
|
||||
"answer": "12"
|
||||
},
|
||||
"q2": {
|
||||
"question": "12 - 8 = ?",
|
||||
"options": [
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4"
|
||||
],
|
||||
"answer": "4"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
"fruit": "Apple",
|
||||
"size": "Large",
|
||||
"quiz": "Red"
|
||||
}
|
||||
|
||||
`
|
||||
|
||||
projections := []string{"quiz","fruit"}
|
||||
|
||||
gjson.ForEachLine(data, func(line gjson.Result) bool{
|
||||
println(line.String())
|
||||
println("+++++++++++")
|
||||
results := gjson.GetMany(line.Raw, projections...)
|
||||
for _, result := range results {
|
||||
println(result.Index, result.Type, result.String())
|
||||
}
|
||||
println("-----------")
|
||||
return true
|
||||
})
|
||||
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user