星期一, 11月 06, 2017

underscore-cli 測試小記

underscore-cli 測試小記

目前學習使用 api 方式來進行計劃使用

但是由於有的時候吐出來的訊息太難看
在 Thomas 建議之下, 想使用 underscore.js ( 官方網站 http://underscorejs.org/  )來處理

根據 Thomas 的說法是安裝 underscore-cli 來處理輸出

官方網站

他必須搭配  node.js 來使用

# zypper  search  nodejs

Loading repository data...
Reading installed packages...

S | Name             | Summary                                          | Type      
--+------------------+--------------------------------------------------+-----------
i | nodejs-common    | Common files for the NodeJS ecosystem            | package   
 | nodejs-common    | Common files for the NodeJS ecosystem            | srcpackage
 | nodejs-packaging | RPM Macros and Utilities for Node.js Packaging   | package   
i | nodejs4          | Evented I/O for V8 JavaScript                    | package   

看起來是有裝 nodejs 的, 所以繼續往下


首先先裝 npm, 之後透過 npm 來進行套件安裝
openSUSE 有 npm4 以及 npm6, 我是裝 npm4

# zypper  install  npm4


underscore-cli 安裝方式

# npm  install  -g  underscore-cli


看指令說明
# underscore  help



實際使用:

未使用 underscore-cli 之前

# curl   http://KONG_SERVER_IP:8001/apis
{"data":[{"methods":["GET"],"uris":["\/api\/3\/action\/package_list"],"id":"f5884e32-bcf4-48bc-9671-dffc79e510d9","hosts":["ipgod.nchc.org.tw"],"preserve_host":false,"created_at":1509519664000,"upstream_connect_timeout":60000,"upstream_url":"http:\/\/ipgod.nchc.org.tw\/api\/3\/action\/package_list","strip_uri":true,"name":"package_list","https_only":false,"http_if_terminated":true,"retries":5,"upstream_send_timeout":60000,"upstream_read_timeout":60000},{"methods":["GET"],"uris":["\/api\/3\/action\/package_show"],"id":"0572b498-b824-4758-9658-8c2b21ac8d6d","hosts":["ipgod.nchc.org.tw"],"preserve_host":false,"created_at":1509521573000,"upstream_connect_timeout":60000,"upstream_url":"http:\/\/ipgod.nchc.org.tw\/api\/3\/action\/package_show","strip_uri":true,"name":"package_data","https_only":false,"http_if_terminated":true,"retries":5,"upstream_send_timeout":60000,"upstream_read_timeout":60000}],"total":2}

使用 underscore-cli 處理

# curl   http://KONG_SERVER_IP/apis  |  underscore  print

 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                Dload  Upload   Total   Spent    Left  Speed
100   917    0   917    0     0   369k      0 --:--:-- --:--:-- --:--:--  447k
{
 "data": [
   {
     "methods": ["GET"],
     "uris": ["/api/3/action/package_list"],
     "id": "f5884e32-bcf4-48bc-9671-dffc79e510d9",
     "hosts": ["ipgod.nchc.org.tw"],
     "preserve_host": false,
     "created_at": 1509519664000,
     "upstream_connect_timeout": 60000,
     "upstream_url": "http://ipgod.nchc.org.tw/api/3/action/package_list",
     "strip_uri": true,
     "name": "package_list",
     "https_only": false,
     "http_if_terminated": true,
     "retries": 5,
     "upstream_send_timeout": 60000,
     "upstream_read_timeout": 60000
   },
   {
     "methods": ["GET"],
     "uris": ["/api/3/action/package_show"],
     "id": "0572b498-b824-4758-9658-8c2b21ac8d6d",
     "hosts": ["ipgod.nchc.org.tw"],
     "preserve_host": false,
     "created_at": 1509521573000,
     "upstream_connect_timeout": 60000,
     "upstream_url": "http://ipgod.nchc.org.tw/api/3/action/package_show",
     "strip_uri": true,
     "name": "package_data",
     "https_only": false,
     "http_if_terminated": true,
     "retries": 5,
     "upstream_send_timeout": 60000,
     "upstream_read_timeout": 60000
   }
 ],
 "total": 2
}


這樣就比較適合人類閱讀了

~ enjoy it

沒有留言: