Gin + GORM + pure-Go SQLite. Users/auth (JWT), API key management with quotas, proxy gateway with weighted channel failover and health checks, usage/billing ledger, cross-protocol conversion (Anthropic Messages / OpenAI Chat Completions / OpenAI Responses), and channel/model admin API. Channels declare native API formats and auto-convert the rest. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package admin
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"go.uber.org/zap"
|
|
"gorm.io/gorm"
|
|
|
|
"openteam/server/internal/pkg/httpx"
|
|
"openteam/server/internal/store"
|
|
)
|
|
|
|
type configHandler struct {
|
|
db *gorm.DB
|
|
log *zap.Logger
|
|
}
|
|
|
|
// Get handles GET /api/v1/admin/config — returns the full config map.
|
|
func (h *configHandler) Get(c *gin.Context) {
|
|
var confs []store.SystemConfig
|
|
if err := h.db.Find(&confs).Error; err != nil {
|
|
h.log.Warn("load config failed", zap.Error(err))
|
|
httpx.Fail(c, http.StatusInternalServerError, "load config failed")
|
|
return
|
|
}
|
|
out := map[string]any{}
|
|
for _, conf := range confs {
|
|
var v any
|
|
if err := json.Unmarshal(conf.Value, &v); err == nil {
|
|
out[conf.Key] = v
|
|
}
|
|
}
|
|
httpx.OK(c, out)
|
|
}
|
|
|
|
// Put handles PUT /api/v1/admin/config — upserts key/value pairs.
|
|
func (h *configHandler) Put(c *gin.Context) {
|
|
var in map[string]any
|
|
if !httpx.Bind(c, &in) {
|
|
return
|
|
}
|
|
for k, v := range in {
|
|
raw, err := json.Marshal(v)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
conf := store.SystemConfig{Key: k, Value: raw}
|
|
if err := h.db.Save(&conf).Error; err != nil {
|
|
h.log.Warn("save config failed", zap.Error(err), zap.String("key", k))
|
|
httpx.Fail(c, http.StatusInternalServerError, "save config failed")
|
|
return
|
|
}
|
|
}
|
|
httpx.OK(c, gin.H{"ok": true})
|
|
}
|