diff --git a/stats.go b/middlewares/stats.go similarity index 92% rename from stats.go rename to middlewares/stats.go index 00aaddbd3..c166799fc 100644 --- a/stats.go +++ b/middlewares/stats.go @@ -1,4 +1,4 @@ -package main +package middlewares import ( "net/http" @@ -16,6 +16,13 @@ type StatsRecorder struct { recentErrors []*statsError } +// NewStatsRecorder returns a new StatsRecorder +func NewStatsRecorder(numRecentErrors int) *StatsRecorder { + return &StatsRecorder{ + numRecentErrors: numRecentErrors, + } +} + // Stats includes all of the stats gathered by the recorder. type Stats struct { RecentErrors []*statsError `json:"recent_errors"` diff --git a/server.go b/server.go index f771f786f..0141b361d 100644 --- a/server.go +++ b/server.go @@ -169,9 +169,7 @@ func (server *Server) startHTTPServers() { for newServerEntryPointName, newServerEntryPoint := range server.serverEntryPoints { serverMiddlewares := []negroni.Handler{server.loggerMiddleware, metrics} if server.globalConfiguration.Web != nil && server.globalConfiguration.Web.Statistics != nil { - statsRecorder = &StatsRecorder{ - numRecentErrors: server.globalConfiguration.Web.Statistics.RecentErrors, - } + statsRecorder = middlewares.NewStatsRecorder(server.globalConfiguration.Web.Statistics.RecentErrors) serverMiddlewares = append(serverMiddlewares, statsRecorder) } if server.globalConfiguration.EntryPoints[newServerEntryPointName].Auth != nil { diff --git a/web.go b/web.go index 432283fb0..b53e72472 100644 --- a/web.go +++ b/web.go @@ -23,7 +23,7 @@ import ( var ( metrics = thoas_stats.New() - statsRecorder *StatsRecorder + statsRecorder *middlewares.StatsRecorder ) // WebProvider is a provider.Provider implementation that provides the UI. @@ -141,7 +141,7 @@ func (provider *WebProvider) Provide(configurationChan chan<- types.ConfigMessag // they are enabled). type healthResponse struct { *thoas_stats.Data - *Stats + *middlewares.Stats } func (provider *WebProvider) getHealthHandler(response http.ResponseWriter, request *http.Request) {