package handlers import ( "context" ) // LoginQuery 登录查询 type LoginQuery struct { APIKey string `json:"api_key" binding:"required"` } // LoginResult 登录结果 type LoginResult struct { Success bool `json:"success"` Message string `json:"message"` Token string `json:"token,omitempty"` } // LoginHandler 登录处理器 type LoginHandler struct { apiKey string } // NewLoginHandler 创建登录处理器 func NewLoginHandler(apiKey string) *LoginHandler { return &LoginHandler{ apiKey: apiKey, } } // Handle 处理登录查询 func (h *LoginHandler) Handle(ctx context.Context, query LoginQuery) (LoginResult, error) { if query.APIKey == h.apiKey { return LoginResult{ Success: true, Message: "登录成功", Token: query.APIKey, }, nil } return LoginResult{ Success: false, Message: "API密钥无效", }, nil }