From 17f1f06070015af313d2ba16a62c004874917b3e Mon Sep 17 00:00:00 2001 From: tbphp Date: Sat, 5 Jul 2025 10:58:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B8=A0=E9=81=93=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/handler/common_handler.go | 22 ++++++++++++++++++++++ internal/handler/handler.go | 2 ++ internal/router/router.go | 2 ++ 3 files changed, 26 insertions(+) create mode 100644 internal/handler/common_handler.go diff --git a/internal/handler/common_handler.go b/internal/handler/common_handler.go new file mode 100644 index 0000000..951feaa --- /dev/null +++ b/internal/handler/common_handler.go @@ -0,0 +1,22 @@ +package handler + +import ( + "gpt-load/internal/channel" + "gpt-load/internal/response" + + "github.com/gin-gonic/gin" +) + +// CommonHandler handles common, non-grouped requests. +type CommonHandler struct{} + +// NewCommonHandler creates a new CommonHandler. +func NewCommonHandler() *CommonHandler { + return &CommonHandler{} +} + +// GetChannelTypes returns a list of available channel types. +func (h *CommonHandler) GetChannelTypes(c *gin.Context) { + channelTypes := channel.GetChannels() + response.Success(c, channelTypes) +} diff --git a/internal/handler/handler.go b/internal/handler/handler.go index 138a462..ff50232 100644 --- a/internal/handler/handler.go +++ b/internal/handler/handler.go @@ -23,6 +23,7 @@ type Server struct { KeyManualValidationService *services.KeyManualValidationService TaskService *services.TaskService KeyService *services.KeyService + CommonHandler *CommonHandler } // NewServer creates a new handler instance @@ -43,6 +44,7 @@ func NewServer( KeyManualValidationService: keyManualValidationService, TaskService: taskService, KeyService: keyService, + CommonHandler: NewCommonHandler(), } } diff --git a/internal/router/router.go b/internal/router/router.go index a16ec51..ef81757 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -99,6 +99,8 @@ func registerPublicAPIRoutes(api *gin.RouterGroup, serverHandler *handler.Server // registerProtectedAPIRoutes 认证API路由 func registerProtectedAPIRoutes(api *gin.RouterGroup, serverHandler *handler.Server, logCleanupHandler *handler.LogCleanupHandler) { + api.GET("/channel-types", serverHandler.CommonHandler.GetChannelTypes) + groups := api.Group("/groups") { groups.POST("", serverHandler.CreateGroup)