You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/08/23 19:10:38 UTC

[2/2] couch-stats commit: updated refs/heads/master to d7310e5

Add sub-stat access at the HTTP layer


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/commit/d7310e54
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/tree/d7310e54
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/diff/d7310e54

Branch: refs/heads/master
Commit: d7310e546baf1685b5b2cd3007136f6d99b573dd
Parents: 1461beb
Author: Paul J. Davis <pa...@gmail.com>
Authored: Sat Aug 23 12:10:11 2014 -0500
Committer: Paul J. Davis <pa...@gmail.com>
Committed: Sat Aug 23 12:10:33 2014 -0500

----------------------------------------------------------------------
 src/couch_stats_httpd.erl | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-stats/blob/d7310e54/src/couch_stats_httpd.erl
----------------------------------------------------------------------
diff --git a/src/couch_stats_httpd.erl b/src/couch_stats_httpd.erl
index b7abe63..fa817f6 100644
--- a/src/couch_stats_httpd.erl
+++ b/src/couch_stats_httpd.erl
@@ -15,12 +15,13 @@
 
 -export([handle_stats_req/1]).
 
-handle_stats_req(#httpd{method='GET', path_parts=[_]}=Req) ->
+handle_stats_req(#httpd{method='GET', path_parts=[_ | Path]}=Req) ->
     Stats0 = couch_stats:fetch(),
     Stats = transform_stats(Stats0),
     Nested = nest(Stats),
-    EJSON = to_ejson(Nested),
-    couch_httpd:send_json(Req, EJSON).
+    EJSON0 = to_ejson(Nested),
+    EJSON1 = extract_path(Path, EJSON0),
+    couch_httpd:send_json(Req, EJSON1).
 
 
 transform_stats(Stats) ->
@@ -75,7 +76,22 @@ to_ejson(NotAProplist) ->
     NotAProplist.
 
 
+extract_path([], EJSON) ->
+    EJSON;
+extract_path([Key | Rest], {Props}) ->
+    case proplists:lookup(Key, Props) of
+        {Key, SubEJSON} ->
+            extract_path(Rest, SubEJSON);
+        none ->
+            null
+    end;
+extract_path([_ | _], _NotAnObject) ->
+    null.
+
+
 maybe_format_key(Key) when is_list(Key) ->
     list_to_binary(Key);
-maybe_format_key(Key) ->
+maybe_format_key(Key) when is_atom(Key) ->
+    list_to_binary(atom_to_list(Key));
+maybe_format_key(Key) when is_binary(Key) ->
     Key.