go_digital_backend/handler/token_handler.go
2025-06-17 20:40:48 +08:00

35 lines
714 B
Go

package handler
import (
"net/http"
"gongzheng_minimax/service"
"github.com/gin-gonic/gin"
)
// TokenHandler handles token generation requests
type TokenHandler struct {
tokenService *service.TokenService
}
// NewTokenHandler creates a new instance of TokenHandler
func NewTokenHandler(tokenService *service.TokenService) *TokenHandler {
return &TokenHandler{
tokenService: tokenService,
}
}
// GenerateToken handles token generation requests
func (h *TokenHandler) GenerateToken(c *gin.Context) {
token, err := h.tokenService.CreateSignature()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, gin.H{
"token": token,
})
}