refactor: clean up project structure

- Remove old review reports (keep latest only)
- Move docs/ to deploy/docs-backup/
- Move performance-testing/ to deploy/
- Clean up test output files
- Organize root directory
This commit is contained in:
Developer
2026-04-06 23:36:03 +08:00
parent 4d71566c0d
commit 349d783fd1
697 changed files with 24114 additions and 163282 deletions

View File

@@ -80,6 +80,9 @@ func (f fakeAPIKeyRepo) ClearGroupIDByGroupID(ctx context.Context, groupID int64
func (f fakeAPIKeyRepo) CountByGroupID(ctx context.Context, groupID int64) (int64, error) {
return 0, errors.New("not implemented")
}
func (f fakeAPIKeyRepo) CountActiveByGroupID(ctx context.Context, groupID int64) (int64, error) {
return 0, errors.New("not implemented")
}
func (f fakeAPIKeyRepo) ListKeysByUserID(ctx context.Context, userID int64) ([]string, error) {
return nil, errors.New("not implemented")
}

View File

@@ -601,6 +601,9 @@ func (r *stubApiKeyRepo) ResetRateLimitWindows(ctx context.Context, id int64) er
func (r *stubApiKeyRepo) GetRateLimitData(ctx context.Context, id int64) (*service.APIKeyRateLimitData, error) {
return nil, nil
}
func (r *stubApiKeyRepo) CountActiveByGroupID(ctx context.Context, groupID int64) (int64, error) {
return 0, errors.New("not implemented")
}
type stubUserSubscriptionRepo struct {
getActive func(ctx context.Context, userID, groupID int64) (*service.UserSubscription, error)

View File

@@ -0,0 +1,47 @@
// Package middleware provides HTTP middleware for metrics collection.
package middleware
import (
"strconv"
"time"
"github.com/Wei-Shaw/sub2api/internal/pkg/metrics"
"github.com/gin-gonic/gin"
)
// PrometheusMetrics returns a Gin middleware that records Prometheus metrics
func PrometheusMetrics() gin.HandlerFunc {
return func(c *gin.Context) {
start := time.Now()
path := c.FullPath()
if path == "" {
path = "unknown"
}
c.Next()
duration := time.Since(start).Seconds()
status := strconv.Itoa(c.Writer.Status())
// Record HTTP metrics
metrics.RecordHTTPRequest(c.Request.Method, path, status, duration)
}
}
// GatewayMetrics returns a Gin middleware that records gateway-specific metrics
func GatewayMetrics() gin.HandlerFunc {
return func(c *gin.Context) {
start := time.Now()
platform := c.GetString("platform")
model := c.GetString("model")
c.Next()
duration := time.Since(start).Seconds()
status := strconv.Itoa(c.Writer.Status())
if platform != "" {
metrics.RecordGatewayRequest(platform, model, status, duration)
}
}
}