Skip to content

Commit

Permalink
fix nil map error
Browse files Browse the repository at this point in the history
fix #67
  • Loading branch information
zyxkad committed May 26, 2024
1 parent 88a74df commit 1ee9544
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (cr *Cluster) getRecordMiddleWare() utils.MiddleWareFunc {
used float64
bytes float64
ua string
isRange bool
skipUA bool
}
recordCh := make(chan record, 1024)

Expand Down Expand Up @@ -228,7 +228,7 @@ func (cr *Cluster) getRecordMiddleWare() utils.MiddleWareFunc {
total++
totalUsed += rec.used
totalBytes += rec.bytes
if !rec.isRange {
if !rec.skipUA {
uas[rec.ua]++
}
case <-disabled:
Expand Down Expand Up @@ -306,7 +306,7 @@ func (cr *Cluster) getRecordMiddleWare() utils.MiddleWareFunc {
rec.bytes = (float64)(srw.Wrote)
ua, _, _ = strings.Cut(ua, " ")
rec.ua, _, _ = strings.Cut(ua, "/")
rec.isRange = extraInfoMap["skip-ua-count"] != nil
rec.skipUA = extraInfoMap["skip-ua-count"] != nil
select {
case recordCh <- rec:
default:
Expand Down
4 changes: 4 additions & 0 deletions notify/stat.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ func (s *Stats) Load(dir string) (err error) {
if err = s.StatData.load(filepath.Join(dir, statsFileName)); err != nil {
return
}
s.subStat = make(map[string]*StatData)

if entries, err := os.ReadDir(filepath.Join(dir, statsDirName)); err == nil {
for _, entry := range entries {
Expand Down Expand Up @@ -336,6 +337,9 @@ func (s *Stats) AddHits(hits int32, bytes int64, name string) {
ss = new(StatData)
ss.Years = make(map[string]statInstData, 2)
ss.Accesses = make(map[string]int, 5)
if s.subStat == nil {
s.subStat = make(map[string]*StatData)
}
s.subStat[name] = ss
}
ss.update(data)
Expand Down

0 comments on commit 1ee9544

Please sign in to comment.