Files
Meshray-Manager/internal/handler/ddns.go
T
zkcoi e9ca2f7d70 fix: rename manager module to git.zkcoi.com/zkcoi/Meshray-Manager
- go.mod module path matches repo zkcoi/Meshray-Manager (case-distinct from zkcoi/Meshray/core)
- rewrite internal imports meshray/{internal,web,pkg} -> Meshray-Manager/... (core refs kept)
- sync README.md / install.sh repo URLs; add CHANGELOG entry
2026-07-15 16:25:46 +08:00

58 lines
1.3 KiB
Go

package handler
import (
"net/http"
"git.zkcoi.com/zkcoi/Meshray-Manager/internal/service"
"github.com/gin-gonic/gin"
)
// DDNSHandler DDNS 相关处理器
type DDNSHandler struct {
ipDetection *service.IPDetectionService
}
// NewDDNSHandler 创建 DDNS 处理器(IP 检测用)
func NewDDNSHandler() *DDNSHandler {
return &DDNSHandler{
ipDetection: service.NewIPDetectionService(),
}
}
// DetectIP 检测公网 IP 地址
// @Summary 检测公网 IP 地址
// @Tags DDNS
// @Accept json
// @Produce json
// @Param record_type query string false "记录类型 (A|AAAA)" default(A)
// @Success 200 {object} map[string]interface{}
// @Router /api/v1/services/ddns/detect-ip [get]
func (h *DDNSHandler) DetectIP(c *gin.Context) {
recordType := c.DefaultQuery("record_type", "A")
if recordType != "A" && recordType != "AAAA" {
c.JSON(http.StatusBadRequest, gin.H{
"code": 400,
"message": "不支持的记录类型,仅支持 A 或 AAAA",
})
return
}
ip, err := h.ipDetection.DetectIP(recordType)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"code": 500,
"message": "检测失败:" + err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{
"code": 0,
"data": gin.H{
"ip": ip,
},
"message": "检测成功",
})
}