50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
// 平台 HTTP API 进程入口,沿用 sample/server 的 BSM 启动规范。
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
"time"
|
|
|
|
"git.apinb.com/bsm-sdk/core/infra"
|
|
"git.apinb.com/bsm-sdk/core/middleware"
|
|
"git.apinb.com/bsm-sdk/core/printer"
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/config"
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/impl"
|
|
"git.apinb.com/heqiapp/platforms/backend/api/internal/routers"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
const serviceKey = "Platform"
|
|
|
|
func main() {
|
|
config.New(serviceKey)
|
|
impl.NewImpl()
|
|
|
|
app := gin.Default()
|
|
middleware.Mode(app)
|
|
app.Use(middleware.Cors())
|
|
app.Use(gin.Recovery())
|
|
app.HEAD("/", infra.Health)
|
|
routers.Register(serviceKey, app)
|
|
|
|
server := &http.Server{Addr: fmt.Sprintf(":%s", config.Spec.Port), Handler: app}
|
|
go func() {
|
|
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
|
panic(err)
|
|
}
|
|
}()
|
|
printer.Success("[BSM - %s] Service Started At: %s", serviceKey, server.Addr)
|
|
|
|
quit := make(chan os.Signal, 1)
|
|
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
|
|
<-quit
|
|
shutdownContext, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
|
defer cancel()
|
|
_ = server.Shutdown(shutdownContext)
|
|
}
|