[ARVADOS] updated: f798c910fa1966b0471451de4f24cc4f55e07290

git at public.curoverse.com git at public.curoverse.com
Fri Nov 14 21:32:08 EST 2014


Summary of changes:
 services/keep/keep_utils.go        | 49 ++++++++++++++++++++++++++++++++++++++
 services/keepstore/handler_test.go |  3 ++-
 services/keepstore/handlers.go     | 35 ---------------------------
 services/keepstore/keepstore.go    |  3 ++-
 4 files changed, 53 insertions(+), 37 deletions(-)
 create mode 100644 services/keep/keep_utils.go

       via  f798c910fa1966b0471451de4f24cc4f55e07290 (commit)
      from  f51138289b7625bde6cc0bb9840ccf681944941a (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit f798c910fa1966b0471451de4f24cc4f55e07290
Author: radhika <radhika at curoverse.com>
Date:   Fri Nov 14 21:29:23 2014 -0500

    4194: refactor REST Router wrapper into a separate package named keep_utils in keep directory.

diff --git a/services/keep/keep_utils.go b/services/keep/keep_utils.go
new file mode 100644
index 0000000..e9163c0
--- /dev/null
+++ b/services/keep/keep_utils.go
@@ -0,0 +1,49 @@
+package keep_utils
+
+// RESTRouterWrapper
+// LoggingResponseWriter
+
+import (
+	"github.com/gorilla/mux"
+	"log"
+	"net/http"
+)
+
+type LoggingResponseWriter struct {
+  status int
+  data []byte
+  http.ResponseWriter
+}
+
+func (loggingWriter *LoggingResponseWriter) WriteHeader(code int) {
+  loggingWriter.status = code
+  loggingWriter.ResponseWriter.WriteHeader(code)
+}
+
+func (loggingWriter *LoggingResponseWriter) Write(data []byte) (int, error){
+  loggingWriter.data = data
+  return loggingWriter.ResponseWriter.Write(data)
+}
+
+type RESTRouterWrapper struct {
+  router *mux.Router
+}
+
+func MakeRESTRouterWrapper(r *mux.Router) (RESTRouterWrapper) {
+  return (RESTRouterWrapper{r})
+}
+
+func (this RESTRouterWrapper) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
+  loggingWriter := LoggingResponseWriter{200, nil, resp}
+  this.router.ServeHTTP(&loggingWriter, req)
+  if loggingWriter.data != nil && loggingWriter.status == 200 {
+    data_len := len(loggingWriter.data)
+    if data_len > 200 {  // this could be a block, so just print the size
+      log.Printf("[%s] %s %s %d %d", req.RemoteAddr, req.Method, req.URL.Path[1:], loggingWriter.status, data_len)
+    } else {  // this could be a hash or status or a small block etc
+      log.Printf("[%s] %s %s %d %s", req.RemoteAddr, req.Method, req.URL.Path[1:], loggingWriter.status, loggingWriter.data)
+    }
+  } else {
+    log.Printf("[%s] %s %s %d", req.RemoteAddr, req.Method, req.URL.Path[1:], loggingWriter.status)
+  }
+}
diff --git a/services/keepstore/handler_test.go b/services/keepstore/handler_test.go
index 2514998..f30287a 100644
--- a/services/keepstore/handler_test.go
+++ b/services/keepstore/handler_test.go
@@ -21,6 +21,7 @@ import (
 	"strings"
 	"testing"
 	"time"
+	"git.curoverse.com/arvados.git/services/keep"
 )
 
 // A RequestTester represents the parameters for an HTTP request to
@@ -750,7 +751,7 @@ func IssueRequest(router *mux.Router, rt *RequestTester) *httptest.ResponseRecor
 	if rt.api_token != "" {
 		req.Header.Set("Authorization", "OAuth2 "+rt.api_token)
 	}
-  routerWrapper := RESTRouterWrapper{router}
+  routerWrapper := keep_utils.MakeRESTRouterWrapper(router)
   routerWrapper.ServeHTTP(response, req)
 	return response
 }
diff --git a/services/keepstore/handlers.go b/services/keepstore/handlers.go
index 49f55e8..bd1ca67 100644
--- a/services/keepstore/handlers.go
+++ b/services/keepstore/handlers.go
@@ -728,38 +728,3 @@ func CanDelete(api_token string) bool {
 func IsDataManagerToken(api_token string) bool {
 	return data_manager_token != "" && api_token == data_manager_token
 }
-
-type LoggingResponseWriter struct {
-  status int
-  data []byte
-  http.ResponseWriter
-}
-
-func (loggingWriter *LoggingResponseWriter) WriteHeader(code int) {
-  loggingWriter.status = code
-  loggingWriter.ResponseWriter.WriteHeader(code)
-}
-
-func (loggingWriter *LoggingResponseWriter) Write(data []byte) (int, error){
-  loggingWriter.data = data
-  return loggingWriter.ResponseWriter.Write(data)
-}
-
-type RESTRouterWrapper struct {
-  router *mux.Router
-}
-
-func (wrapper *RESTRouterWrapper) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
-  loggingWriter := LoggingResponseWriter{200, nil, resp}
-  wrapper.router.ServeHTTP(&loggingWriter, req)
-  if loggingWriter.data != nil && loggingWriter.status == 200 {
-    data_len := len(loggingWriter.data)
-    if data_len > 200 {  // this could be a block, so just print the size
-      log.Printf("[%s] %s %s %d %d", req.RemoteAddr, req.Method, req.URL.Path[1:], loggingWriter.status, data_len)
-    } else {  // this could be a hash or status or a small block etc
-      log.Printf("[%s] %s %s %d %s", req.RemoteAddr, req.Method, req.URL.Path[1:], loggingWriter.status, loggingWriter.data)
-    }
-  } else {
-    log.Printf("[%s] %s %s %d", req.RemoteAddr, req.Method, req.URL.Path[1:], loggingWriter.status)
-  }
-}
diff --git a/services/keepstore/keepstore.go b/services/keepstore/keepstore.go
index eafcc23..6d149f7 100644
--- a/services/keepstore/keepstore.go
+++ b/services/keepstore/keepstore.go
@@ -13,6 +13,7 @@ import (
 	"strings"
 	"syscall"
 	"time"
+	"git.curoverse.com/arvados.git/services/keep"
 )
 
 // ======================
@@ -263,7 +264,7 @@ func main() {
 	KeepVM = MakeRRVolumeManager(goodvols)
 
 	// Tell the built-in HTTP server to direct all requests to the REST router.
-  routerWrapper := RESTRouterWrapper{MakeRESTRouter()}
+  routerWrapper := keep_utils.MakeRESTRouterWrapper(MakeRESTRouter())
   http.HandleFunc("/", func(resp http.ResponseWriter, req *http.Request) {
     routerWrapper.ServeHTTP(resp, req)
   })

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list