github.com/yusys-cloud/go-jsonstore-rest@v0.0.0-20230228115429-0a54aa4a27a6/README.md (about)

     1  # Go-Jsonstore-Rest
     2  
     3  A quick and easy way to setup a RESTful JSON DATASTORE server for small projects.
     4  
     5  ## Quick Start
     6  
     7  Binary Download
     8  
     9  https://github.com/yusys-cloud/go-jsonstore-rest/releases 
    10  
    11  Startup
    12  
    13  ``` 
    14  ./go-jsonstore-rest
    15  ```
    16  
    17  Replace ./json-db with the path to the drive or directory in which you want to store data.
    18  
    19  ```
    20  ./go-jsonstore-rest --path=./json-db --port=9999 
    21  ```
    22  ## Installation
    23  ``` 
    24  go get github.com/yusys-cloud/go-jsonstore-rest
    25  ```
    26  ## Usage
    27  
    28  ### Base Codes
    29  ```
    30  import (
    31  	"github.com/gin-gonic/gin"
    32  	"github.com/yusys-cloud/go-jsonstore-rest/rest"
    33  	"net/http"
    34  )
    35  func main() {
    36  	r := gin.Default()
    37  	//REST-APIs-json
    38  	rest.NewJsonStoreRest("./api-data", r)
    39  	r.Run(":9991")
    40  }
    41  ```
    42  
    43  ## RESTful API
    44  - key:value store/cache
    45  ``` 
    46  curl localhost:9999/api/cache -X POST -d '{"k":"k1","v":"hellow world"}'
    47  ```
    48  ``` 
    49  curl localhost:9999/api/cache/k1
    50  ```
    51  - First In, First Out (FIFO)
    52  ``` 
    53  curl 'localhost:9999/api/fifo?size=10' -X POST -d '{"k":"key1","v":"hellow world"}'
    54  ```
    55  ``` 
    56  curl localhost:9999/api/kv/meta/key1
    57  ```
    58  - RESTful JSON DATASTORE
    59  
    60  Create
    61  ``` 
    62  curl localhost:9999/api/kv/meta/node -X POST -d '{"ip": "192.168.x.x","name":"redis-n1","idc":"default","lable":"Redis"}' --header "Content-Type: application/json"
    63  ```
    64  Read
    65  ```
    66  curl localhost:9999/api/kv/meta/node
    67  ```
    68  Update
    69  ```
    70  curl localhost:9999/api/kv/meta/node/node:1429991523109310464 -X PUT -d '{"ip": "192.168.49.69","name":"redis-n2","idc":"default","lable":"Redis"}' --header "Content-Type: application/json"
    71  ```
    72  Delete
    73  ```
    74  curl localhost:9999/api/kv/meta/node/node:1429991523109310464 -X DELETE
    75  ```
    76  Delete All
    77  ```
    78  curl localhost:9999/api/kv/meta/node -X DELETE
    79  ```
    80  Search
    81  ```
    82  curl http://localhost:9999/api/search?b=meta&k=node&key=v.name&value=linux&shortBy=weight,desc&page=1&size=10
    83  ```
    84  /api/kv/:b/:k 
    85  - 参数 b 为存储的json文件名,类似数据库名称
    86  - 参数 k 为存储文件中json对象数组名,类似数据库中表名称
    87  
    88  /api/search?b=node&k=node&key=v.name&value=linux&shortBy=v.weight,desc&page=1&size=2
    89  
    90  /api/search?b=meta&k=node&key=v.name,v.lable&value=zk|zk2,zk&relation=like
    91  
    92  - 参数 key 为搜索json对象中字段名称
    93  - 参数 value 为搜索json对象字段的搜索值
    94  - 参数 key 为json对象的搜索字段名称,需多层json key的完整路径值,如:v.name
    95  - 参数 relation 为查询关系,默认为equal精准查询,可选like模糊查询
    96  - 参数 value 为json对象字段的搜索值
    97  
    98  ``` 
    99  [GIN-debug] POST   /api/kv/:b/:k             --> github.com/yusys-cloud/go-jsonstore-rest/rest.(*Storage).create-fm (3 handlers)
   100  [GIN-debug] GET    /api/kv/:b/:k             --> github.com/yusys-cloud/go-jsonstore-rest/rest.(*Storage).readAll-fm (3 handlers)
   101  [GIN-debug] GET    /api/kv/:b/:k/:kid        --> github.com/yusys-cloud/go-jsonstore-rest/rest.(*Storage).read-fm (3 handlers)
   102  [GIN-debug] PUT    /api/kv/:b/:k/:kid        --> github.com/yusys-cloud/go-jsonstore-rest/rest.(*Storage).update-fm (3 handlers)
   103  [GIN-debug] PUT    /api/kv/:b/:k/:kid/weight --> github.com/yusys-cloud/go-jsonstore-rest/rest.(*Storage).updateWeight-fm (3 handlers)
   104  [GIN-debug] DELETE /api/kv/:b/:k/:kid        --> github.com/yusys-cloud/go-jsonstore-rest/rest.(*Storage).delete-fm (3 handlers)
   105  [GIN-debug] DELETE /api/kv/:b/:k             --> github.com/yusys-cloud/go-jsonstore-rest/rest.(*Storage).deleteAll-fm (3 handlers)
   106  [GIN-debug] GET    /api/search               --> github.com/yusys-cloud/go-jsonstore-rest/rest.(*Storage).search-fm (3 handlers)
   107  
   108  ```
   109  <img width="550px" src="./docs/static/json-rest-crud-costtime.jpg">
   110  <img width="550px" src="./docs/static/crud-time-ms.jpg">
   111  
   112  ## Benchmarks
   113  - BenchmarkQuery100-12    	       1	2,102,479,566 ns/op
   114  - BenchmarkCreate100-12    	       1	1082093859 ns/op