63 lines
1.5 KiB
Go
63 lines
1.5 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"xy_sh/internal/biz"
|
|
"xy_sh/internal/data/impl"
|
|
service2 "xy_sh/internal/service"
|
|
"xy_sh/utils"
|
|
"xy_sh/ymt_v3"
|
|
|
|
"xy_sh/internal/config"
|
|
"xy_sh/internal/router"
|
|
"xy_sh/pkg/crypto"
|
|
|
|
"github.com/go-viper/mapstructure/v2"
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
func main() {
|
|
cfgPath := flag.String("config", "./config/config_test.yaml", "Path to configuration file")
|
|
cfg, err := config.LoadConfig(*cfgPath)
|
|
if err != nil {
|
|
log.Fatalf("加载配置失败: %v", err)
|
|
}
|
|
crypto.InitCrypto(cfg.SM3Salt, cfg.SM4Key)
|
|
|
|
app := fiber.New(fiber.Config{
|
|
AppName: "XY SH API Server",
|
|
ReadTimeout: cfg.ReadTimeout,
|
|
WriteTimeout: cfg.WriteTimeout,
|
|
})
|
|
|
|
db, cleanup := utils.NewGormDb(cfg)
|
|
defer cleanup()
|
|
orderImpl := impl.NewOrderImpl(db)
|
|
logImpl := impl.NewLogImpl(db)
|
|
ymt, err := ymtClient(cfg.Ymt)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
bizs := biz.NewOrderStore(orderImpl, ymt, cfg)
|
|
service := service2.NewOrder(bizs, logImpl)
|
|
router.SetupRoutes(app, service)
|
|
|
|
log.Printf("服务启动,监听端口: %s", cfg.ServerPort)
|
|
if err := app.Listen(":" + cfg.ServerPort); err != nil {
|
|
log.Fatalf("服务启动失败: %v", err)
|
|
}
|
|
}
|
|
|
|
func ymtClient(cfg config.Ymt) (*ymt_v3.Client, error) {
|
|
return ymt_v3.NewClient(&ymt_v3.ClientConfig{
|
|
AppID: cfg.AppID,
|
|
PrivateKey: cfg.PrivateKey,
|
|
PublicKey: cfg.PublicKey,
|
|
Key: cfg.Key,
|
|
EncryptType: ymt_v3.EncryptType(cfg.EncryptType),
|
|
Env: ymt_v3.Env(cfg.Env),
|
|
})
|
|
}
|