diff --git a/apis/common.api b/apis/common.api index e965d5e..db935f4 100644 --- a/apis/common.api +++ b/apis/common.api @@ -87,6 +87,11 @@ type ( Total int64 `json:"total"` List []SubscribeClient `json:"list"` } + HeartbeatResponse { + Status bool `json:"status"` + Message string `json:"message,omitempty"` + Timestamp int64 `json:"timestamp,omitempty"` + } ) @server ( @@ -130,5 +135,9 @@ service ppanel { @doc "Get Client" @handler GetClient get /client returns (GetSubscribeClientResponse) + + @doc "Heartbeat" + @handler Heartbeat + get /heartbeat returns (HeartbeatResponse) } diff --git a/internal/handler/common/heartbeatHandler.go b/internal/handler/common/heartbeatHandler.go new file mode 100644 index 0000000..d72d771 --- /dev/null +++ b/internal/handler/common/heartbeatHandler.go @@ -0,0 +1,18 @@ +package common + +import ( + "github.com/gin-gonic/gin" + "github.com/perfect-panel/server/internal/logic/common" + "github.com/perfect-panel/server/internal/svc" + "github.com/perfect-panel/server/pkg/result" +) + +// Heartbeat +func HeartbeatHandler(svcCtx *svc.ServiceContext) func(c *gin.Context) { + return func(c *gin.Context) { + + l := common.NewHeartbeatLogic(c.Request.Context(), svcCtx) + resp, err := l.Heartbeat() + result.HttpResult(c, resp, err) + } +} diff --git a/internal/handler/routes.go b/internal/handler/routes.go index 282110d..5e0364b 100644 --- a/internal/handler/routes.go +++ b/internal/handler/routes.go @@ -638,6 +638,9 @@ func RegisterHandlers(router *gin.Engine, serverCtx *svc.ServiceContext) { // Get Client commonGroupRouter.GET("/client", common.GetClientHandler(serverCtx)) + // Heartbeat + commonGroupRouter.GET("/heartbeat", common.HeartbeatHandler(serverCtx)) + // Get verification code commonGroupRouter.POST("/send_code", common.SendEmailCodeHandler(serverCtx)) diff --git a/internal/logic/common/heartbeatLogic.go b/internal/logic/common/heartbeatLogic.go new file mode 100644 index 0000000..1bfb081 --- /dev/null +++ b/internal/logic/common/heartbeatLogic.go @@ -0,0 +1,33 @@ +package common + +import ( + "context" + "time" + + "github.com/perfect-panel/server/internal/svc" + "github.com/perfect-panel/server/internal/types" + "github.com/perfect-panel/server/pkg/logger" +) + +type HeartbeatLogic struct { + logger.Logger + ctx context.Context + svcCtx *svc.ServiceContext +} + +// NewHeartbeatLogic Heartbeat +func NewHeartbeatLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HeartbeatLogic { + return &HeartbeatLogic{ + Logger: logger.WithContext(ctx), + ctx: ctx, + svcCtx: svcCtx, + } +} + +func (l *HeartbeatLogic) Heartbeat() (resp *types.HeartbeatResponse, err error) { + return &types.HeartbeatResponse{ + Status: true, + Message: "service is alive", + Timestamp: time.Now().Unix(), + }, nil +} diff --git a/internal/types/types.go b/internal/types/types.go index 79c3490..b8b39ab 100644 --- a/internal/types/types.go +++ b/internal/types/types.go @@ -1158,6 +1158,12 @@ type HasMigrateSeverNodeResponse struct { HasMigrate bool `json:"has_migrate"` } +type HeartbeatResponse struct { + Status bool `json:"status"` + Message string `json:"message,omitempty"` + Timestamp int64 `json:"timestamp,omitempty"` +} + type Hysteria2 struct { Port int `json:"port" validate:"required"` HopPorts string `json:"hop_ports" validate:"required"`