load counter path from env
env
This commit is contained in:
parent
fb876226dd
commit
be89141c06
2 changed files with 15 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"log/slog"
|
||||
"os"
|
||||
"sync"
|
||||
|
|
@ -18,7 +19,13 @@ type RequestCounter struct {
|
|||
}
|
||||
|
||||
// NewRequestCounter creates a new request counter with periodic snapshots
|
||||
func NewRequestCounter(snapshotPath string, snapshotInterval time.Duration) (*RequestCounter, error) {
|
||||
func NewRequestCounter(snapshotInterval time.Duration) (*RequestCounter, error) {
|
||||
snapshotPath := os.Getenv("REQUEST_COUNTS_PATH")
|
||||
if snapshotPath == "" {
|
||||
err := errors.New("REQUEST_COUNTS_PATH environment variable must be set and non-empty")
|
||||
slog.Error("failed to initialize request counter", "error", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
c := &RequestCounter{
|
||||
counts: make(map[string]int64),
|
||||
snapshotPath: snapshotPath,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue