feat:ok
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
package infra
|
||||
|
||||
import "github.com/gofiber/fiber/v2"
|
||||
|
||||
func Health(ctx *fiber.Ctx) error {
|
||||
return ctx.SendStatus(200)
|
||||
}
|
||||
9
infra/health.go
Normal file
9
infra/health.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Health(ctx *gin.Context) {
|
||||
ctx.String(200, "ok", nil)
|
||||
}
|
||||
16
infra/new.go
16
infra/new.go
@@ -1,16 +0,0 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"git.apinb.com/bsm-sdk/core/cache/redis"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
var (
|
||||
DB *gorm.DB
|
||||
RedisCache *redis.RedisClient
|
||||
)
|
||||
|
||||
func New(db *gorm.DB, redisCache *redis.RedisClient) {
|
||||
DB = db
|
||||
RedisCache = redisCache
|
||||
}
|
||||
38
infra/response.go
Normal file
38
infra/response.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package infra
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var Response *Reply
|
||||
|
||||
type Reply struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data any `json:"data"`
|
||||
}
|
||||
|
||||
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
||||
reply.Code = 200
|
||||
if data == nil {
|
||||
reply.Data = ""
|
||||
}
|
||||
|
||||
ctx.JSON(200, reply)
|
||||
return
|
||||
}
|
||||
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
||||
reply.Code = 500
|
||||
// Status code defaults to 500
|
||||
e, ok := status.FromError(err)
|
||||
if ok {
|
||||
reply.Code = int(e.Code())
|
||||
}
|
||||
|
||||
reply.Msg = e.Message()
|
||||
|
||||
// Send error
|
||||
ctx.JSON(200, reply)
|
||||
return
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
var (
|
||||
Service service
|
||||
RootPrefix string = "/services/"
|
||||
RootPrefix string = "/bsm_services/"
|
||||
)
|
||||
|
||||
type service struct{}
|
||||
@@ -37,10 +37,10 @@ func (s *service) Register(cli *clientv3.Client, serviceName string, port int) e
|
||||
return err
|
||||
}
|
||||
|
||||
print.Info("[Traingo Register] Service Key: %s", key)
|
||||
print.Info("[Traingo Register] Service Val: %s", serviceAddr)
|
||||
print.Info("[BSM Register] Service Key: %s", key)
|
||||
print.Info("[BSM Register] Service Val: %s", serviceAddr)
|
||||
|
||||
print.Success("[Traingo Register] Service Register Complete.")
|
||||
print.Success("[BSM Register] Service Register Complete.")
|
||||
|
||||
go func() {
|
||||
for keepAliveResp := range keepAliveChan {
|
||||
|
||||
Reference in New Issue
Block a user