Move stats to a separate package

This commit is contained in:
Igor Chubin 2022-12-03 15:39:34 +01:00
parent aef41c375e
commit 0d42c23d5b
2 changed files with 6 additions and 5 deletions

View file

@ -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,
}

View file

@ -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(),