使用KV存储实现指标统计

This commit is contained in:
刘祥超
2024-04-02 19:54:04 +08:00
parent 750aafdea1
commit e5c5234be8
21 changed files with 1561 additions and 612 deletions

View File

@@ -0,0 +1,24 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package metrics
import (
"encoding/json"
"errors"
)
type ItemEncoder[T interface{ *Stat }] struct {
}
func (this *ItemEncoder[T]) Encode(value T) ([]byte, error) {
return json.Marshal(value)
}
func (this *ItemEncoder[T]) EncodeField(value T, fieldName string) ([]byte, error) {
return nil, errors.New("invalid field name '" + fieldName + "'")
}
func (this *ItemEncoder[T]) Decode(valueBytes []byte) (value T, err error) {
err = json.Unmarshal(valueBytes, &value)
return
}