mirror of
https://github.com/fluencelabs/jsonpath
synced 2025-04-25 09:22:19 +00:00
content_by_lua_file directive 테스트 추가
This commit is contained in:
parent
422a23ee57
commit
8c24411c3f
1
lua/.gitignore
vendored
1
lua/.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
.vscode
|
.vscode
|
||||||
/target/
|
/target/
|
||||||
Cargo.lock
|
Cargo.lock
|
||||||
|
docker_example/ab_results/**
|
@ -1,12 +1,13 @@
|
|||||||
lua_package_path '/etc/jsonpath/?.lua;;';
|
lua_package_path '/etc/jsonpath/?.lua;;';
|
||||||
|
|
||||||
|
access_log /var/log/nginx_access.log;
|
||||||
error_log /var/log/nginx_error.log info;
|
error_log /var/log/nginx_error.log info;
|
||||||
|
|
||||||
server {
|
server {
|
||||||
listen 80;
|
listen 80;
|
||||||
server_name localhost;
|
server_name localhost;
|
||||||
|
|
||||||
location / {
|
location /0 {
|
||||||
default_type text/html;
|
default_type text/html;
|
||||||
|
|
||||||
content_by_lua '
|
content_by_lua '
|
||||||
@ -19,6 +20,12 @@ server {
|
|||||||
';
|
';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /1 {
|
||||||
|
default_type text/html;
|
||||||
|
|
||||||
|
content_by_lua_file /etc/jsonpath/testa.lua;
|
||||||
|
}
|
||||||
|
|
||||||
location /example {
|
location /example {
|
||||||
root /etc/jsonpath/example;
|
root /etc/jsonpath/example;
|
||||||
}
|
}
|
||||||
|
3
lua/docker_example/init.lua
Normal file
3
lua/docker_example/init.lua
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
local jsonpath = require("jsonpath")
|
||||||
|
jsonpath.init("/etc/jsonpath/libjsonpath_lib.so")
|
||||||
|
ngx.log(ngx.INFO, "loaded libjsonpath_lib.so")
|
@ -4,12 +4,47 @@
|
|||||||
|
|
||||||
set -v
|
set -v
|
||||||
|
|
||||||
|
docker kill jsonpath
|
||||||
|
|
||||||
docker run -d --rm --name jsonpath \
|
docker run -d --rm --name jsonpath \
|
||||||
-v "${PWD}/../../benchmark/example.json":/etc/jsonpath/example/example.json:ro \
|
-v "${PWD}/../../benchmark/example.json":/etc/jsonpath/example/example.json:ro \
|
||||||
-v "${PWD}/../jsonpath.lua":/etc/jsonpath/jsonpath.lua:ro \
|
-v "${PWD}/../jsonpath.lua":/etc/jsonpath/jsonpath.lua:ro \
|
||||||
|
-v "${PWD}/testa.lua":/etc/jsonpath/testa.lua:ro \
|
||||||
|
-v "${PWD}/init.lua":/etc/jsonpath/init.lua:ro \
|
||||||
-v "${PWD}/../target/release/deps/libjsonpath_lib.so":/etc/jsonpath/libjsonpath_lib.so:ro \
|
-v "${PWD}/../target/release/deps/libjsonpath_lib.so":/etc/jsonpath/libjsonpath_lib.so:ro \
|
||||||
-v "${PWD}/default.conf":/etc/nginx/conf.d/default.conf \
|
-v "${PWD}/default.conf":/etc/nginx/conf.d/default.conf \
|
||||||
-p 8080:80 \
|
-p 8080:80 \
|
||||||
openresty/openresty:bionic
|
openresty/openresty:bionic
|
||||||
|
|
||||||
docker exec -it jsonpath bash -c "curl localhost"
|
paths=(
|
||||||
|
"$.store.book[*].author"
|
||||||
|
"$..author"
|
||||||
|
"$.store.*"
|
||||||
|
"$.store..price"
|
||||||
|
"$..book[2]"
|
||||||
|
"$..book[-2]"
|
||||||
|
"$..book[0,1]"
|
||||||
|
"$..book[:2]"
|
||||||
|
"$..book[1:2]"
|
||||||
|
"$..book[-2:]"
|
||||||
|
"$..book[2:]"
|
||||||
|
"$..book[?(@.isbn)]"
|
||||||
|
"$.store.book[?(@.price == 10)]"
|
||||||
|
"$..*"
|
||||||
|
"$..book[ ?( (@.price < 13 || $.store.bicycle.price < @.price) && @.price <=10 ) ]"
|
||||||
|
"$.store.book[?( (@.price < 10 || @.price > 10) && @.price > 10 )]"
|
||||||
|
)
|
||||||
|
|
||||||
|
encoded_paths=()
|
||||||
|
|
||||||
|
for i in "${!paths[@]}"
|
||||||
|
do
|
||||||
|
encoded_paths+=("$(node --eval "console.log(encodeURIComponent('${paths[$i]}'))")")
|
||||||
|
curl http://localhost:8080/1?path="${encoded_paths[$i]}"
|
||||||
|
done
|
||||||
|
|
||||||
|
for i in "${!encoded_paths[@]}"
|
||||||
|
do
|
||||||
|
ab -n 1000 -c 10 http://localhost:8080/1?path="${encoded_paths[$i]}" > ab_results/"${paths[$i]}".txt
|
||||||
|
done
|
||||||
|
|
||||||
|
14
lua/docker_example/testa.lua
Normal file
14
lua/docker_example/testa.lua
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
require("init")
|
||||||
|
local jsonpath = require("jsonpath")
|
||||||
|
|
||||||
|
local args = ngx.req.get_uri_args()
|
||||||
|
|
||||||
|
local path = args['path']
|
||||||
|
if(path == nil or path == '') then
|
||||||
|
return ngx.exit(400)
|
||||||
|
end
|
||||||
|
|
||||||
|
local template = jsonpath.compile(path)
|
||||||
|
local data = ngx.location.capture("/example.json")
|
||||||
|
local result = template(data.body)
|
||||||
|
ngx.say(result)
|
Loading…
x
Reference in New Issue
Block a user