From 9e6cfdf9668157ec7ff566c670ce293b18d2bc83 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Wed, 9 May 2018 20:26:39 -0700 Subject: basic sentry; middleware; clacks-overhead --- golang/restapi/configure_fatcat.go | 23 ++++++++++++++++++++++- golang/restapi/doc.go | 1 - golang/restapi/embedded_spec.go | 6 ++---- golang/restapi/server.go | 3 +-- 4 files changed, 25 insertions(+), 8 deletions(-) (limited to 'golang/restapi') diff --git a/golang/restapi/configure_fatcat.go b/golang/restapi/configure_fatcat.go index 418400fc..7398ad26 100644 --- a/golang/restapi/configure_fatcat.go +++ b/golang/restapi/configure_fatcat.go @@ -10,6 +10,10 @@ import ( runtime "github.com/go-openapi/runtime" middleware "github.com/go-openapi/runtime/middleware" graceful "github.com/tylerb/graceful" + "github.com/carbocation/interpose" + "github.com/carbocation/interpose/adaptors" + //"github.com/getsentry/raven-go" + "github.com/meatballhat/negroni-logrus" "git.archive.org/bnewbold/fatcat/golang/restapi/operations" ) @@ -67,5 +71,22 @@ func setupMiddlewares(handler http.Handler) http.Handler { // The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document. // So this is a good place to plug in a panic handling middleware, logging and metrics func setupGlobalMiddleware(handler http.Handler) http.Handler { - return handler + + middle := interpose.New() + + // sentry and upstream + //middle.UseHandler(sentry.Recovery(raven.DefaultClient, false)) + + // logging + negroniMiddleware := negronilogrus.NewMiddleware() + middle.Use(adaptors.FromNegroni(negroniMiddleware)) + + // add clacks + middle.UseHandler(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { + rw.Header().Set("X-Clacks-Overhead:", "GNU Aaron Swartz, John Perry Barlow") + })) + + middle.UseHandler(handler) + + return middle } diff --git a/golang/restapi/doc.go b/golang/restapi/doc.go index 9896c2da..e18461a8 100644 --- a/golang/restapi/doc.go +++ b/golang/restapi/doc.go @@ -7,7 +7,6 @@ A scalable, versioned, API-oriented catalog of bibliographic entities and file m Schemes: http - https Host: api.fatcat.wiki BasePath: /v0 Version: 0.1.0 diff --git a/golang/restapi/embedded_spec.go b/golang/restapi/embedded_spec.go index 1b193eb9..6a6cf356 100644 --- a/golang/restapi/embedded_spec.go +++ b/golang/restapi/embedded_spec.go @@ -25,8 +25,7 @@ func init() { "application/json" ], "schemes": [ - "http", - "https" + "http" ], "swagger": "2.0", "info": { @@ -140,8 +139,7 @@ func init() { "application/json" ], "schemes": [ - "http", - "https" + "http" ], "swagger": "2.0", "info": { diff --git a/golang/restapi/server.go b/golang/restapi/server.go index a11c94c6..6fb4f3b9 100644 --- a/golang/restapi/server.go +++ b/golang/restapi/server.go @@ -15,11 +15,11 @@ import ( "sync/atomic" "time" - log "github.com/sirupsen/logrus" "github.com/go-openapi/runtime/flagext" "github.com/go-openapi/swag" flags "github.com/jessevdk/go-flags" graceful "github.com/tylerb/graceful" + log "github.com/sirupsen/logrus" // manual hack for now (bnewbold) "git.archive.org/bnewbold/fatcat/golang/restapi/operations" ) @@ -35,7 +35,6 @@ var defaultSchemes []string func init() { defaultSchemes = []string{ schemeHTTP, - schemeHTTPS, } } -- cgit v1.2.3