From 0d42c23d5b82655f84d0111ac7eb174577d3fb27 Mon Sep 17 00:00:00 2001 From: Igor Chubin Date: Sat, 3 Dec 2022 15:39:34 +0100 Subject: [PATCH] Move stats to a separate package --- cmd/processRequest.go | 5 +++-- cmd/stat.go => internal/stats/stats.go | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) rename cmd/stat.go => internal/stats/stats.go (96%) diff --git a/cmd/processRequest.go b/cmd/processRequest.go index a010978..0aa6085 100644 --- a/cmd/processRequest.go +++ b/cmd/processRequest.go @@ -14,6 +14,7 @@ import ( "github.com/chubin/wttr.in/internal/config" "github.com/chubin/wttr.in/internal/routing" + "github.com/chubin/wttr.in/internal/stats" lru "github.com/hashicorp/golang-lru" ) @@ -32,7 +33,7 @@ type RequestProcessor struct { peakRequest30 sync.Map peakRequest60 sync.Map lruCache *lru.Cache - stats *Stats + stats *stats.Stats router routing.Router upstreamTransport *http.Transport config *config.Config @@ -59,7 +60,7 @@ func NewRequestProcessor(config *config.Config) (*RequestProcessor, error) { rp := &RequestProcessor{ lruCache: lruCache, - stats: NewStats(), + stats: stats.New(), upstreamTransport: transport, config: config, } diff --git a/cmd/stat.go b/internal/stats/stats.go similarity index 96% rename from cmd/stat.go rename to internal/stats/stats.go index 73e4647..a030add 100644 --- a/cmd/stat.go +++ b/internal/stats/stats.go @@ -1,4 +1,4 @@ -package main +package stats import ( "bytes" @@ -17,8 +17,8 @@ type Stats struct { startTime time.Time } -// NewStats returns new Stats. -func NewStats() *Stats { +// New returns new Stats. +func New() *Stats { return &Stats{ v: map[string]int{}, startTime: time.Now(),