- 新增 GET /admin/ops/metrics 与进程内请求统计中间件 - 运维页展示 CPU/内存/磁盘、24h 曲线与 WS/DB/存储状态 - 去掉未使用的消息队列占位项
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package storage
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
"sync"
|
|
)
|
|
|
|
// MemoryStorage 测试用内存存储
|
|
type MemoryStorage struct {
|
|
mu sync.RWMutex
|
|
data map[string][]byte
|
|
base string
|
|
}
|
|
|
|
func NewMemory(publicBase string) *MemoryStorage {
|
|
return &MemoryStorage{
|
|
data: make(map[string][]byte),
|
|
base: NormalizePublicBase(publicBase),
|
|
}
|
|
}
|
|
|
|
func (m *MemoryStorage) Put(_ context.Context, key string, r io.Reader, _ int64, _ string) (string, error) {
|
|
b, err := io.ReadAll(r)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
m.mu.Lock()
|
|
m.data[key] = b
|
|
m.mu.Unlock()
|
|
return m.base + "/" + key, nil
|
|
}
|
|
|
|
func (m *MemoryStorage) Delete(_ context.Context, key string) error {
|
|
m.mu.Lock()
|
|
delete(m.data, key)
|
|
m.mu.Unlock()
|
|
return nil
|
|
}
|
|
|
|
func (m *MemoryStorage) PublicBase() string { return m.base }
|
|
|
|
func (m *MemoryStorage) EnsureBucket(context.Context) error { return nil }
|
|
|
|
func (m *MemoryStorage) HealthCheck(context.Context) error { return nil }
|
|
|
|
func (m *MemoryStorage) Get(key string) ([]byte, error) {
|
|
m.mu.RLock()
|
|
defer m.mu.RUnlock()
|
|
b, ok := m.data[key]
|
|
if !ok {
|
|
return nil, fmt.Errorf("not found")
|
|
}
|
|
return bytes.Clone(b), nil
|
|
}
|