合并最新 main
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
+21
-3
@@ -18,6 +18,8 @@ import (
|
||||
"github.com/baicai2026-baicai/goods/api/internal/adminstore"
|
||||
"github.com/baicai2026-baicai/goods/api/internal/adminweb"
|
||||
"github.com/baicai2026-baicai/goods/api/internal/auth"
|
||||
"github.com/baicai2026-baicai/goods/api/internal/cache"
|
||||
"github.com/baicai2026-baicai/goods/api/internal/clientip"
|
||||
"github.com/baicai2026-baicai/goods/api/internal/ratelimit"
|
||||
)
|
||||
|
||||
@@ -37,6 +39,18 @@ func main() {
|
||||
if err != nil || backflowRate < 1 {
|
||||
log.Fatalf("invalid GOODS_BACKFLOW_RATE_PER_HOUR: must be a positive integer")
|
||||
}
|
||||
tokenTTL := 12 * time.Hour
|
||||
if value := os.Getenv("GOODS_ADMIN_TOKEN_TTL"); value != "" {
|
||||
parsed, err := time.ParseDuration(value)
|
||||
if err != nil || parsed <= 0 {
|
||||
log.Fatalf("invalid GOODS_ADMIN_TOKEN_TTL %q: expected a positive duration", value)
|
||||
}
|
||||
tokenTTL = parsed
|
||||
}
|
||||
clientIPs, err := clientip.Parse(getenv("OPENGOODS_TRUSTED_PROXIES", ""))
|
||||
if err != nil {
|
||||
log.Fatalf("invalid OPENGOODS_TRUSTED_PROXIES: %v", err)
|
||||
}
|
||||
|
||||
// Password: prefer a bcrypt hash; otherwise hash a plaintext password.
|
||||
var passwordHash []byte
|
||||
@@ -74,11 +88,15 @@ func main() {
|
||||
log.Printf("warning: database not reachable at startup: %v", err)
|
||||
}
|
||||
|
||||
authn := auth.New(username, passwordHash, secret, 12*time.Hour)
|
||||
usage := ratelimit.New(getenv("OPENGOODS_REDIS_URL", "redis://localhost:6379/0"))
|
||||
authn := auth.New(username, passwordHash, secret, tokenTTL)
|
||||
redisURL := getenv("OPENGOODS_REDIS_URL", "redis://localhost:6379/0")
|
||||
usage := ratelimit.New(redisURL)
|
||||
readCache := cache.New(redisURL)
|
||||
h := adminhandler.New(adminstore.New(pool), authn, basePath, adminweb.Dist()).
|
||||
WithUsage(usage).
|
||||
WithBackflowRate(backflowRate)
|
||||
WithBackflowRate(backflowRate).
|
||||
WithCache(readCache).
|
||||
WithClientIP(clientIPs)
|
||||
|
||||
srv := &http.Server{
|
||||
Addr: addr,
|
||||
|
||||
Reference in New Issue
Block a user