好像有戏

This commit is contained in:
des
2026-01-22 00:12:24 +08:00
parent 27c89d66f7
commit d09d9d9f1a
4 changed files with 54 additions and 42 deletions

View File

@@ -1,26 +0,0 @@
package application
import (
"context"
"github.com/gin-gonic/gin"
"github.com/go-spring/spring-core/gs"
)
type Controller interface {
RegisterRoute()
}
type AppPak struct {
core *gin.Engine
}
func (s *AppPak) ListenAndServe(sig gs.ReadySignal) error {
s.core = gin.Default()
s.core.Run("7777")
return nil
}
func (_ *AppPak) Shutdown(ctx context.Context) error {
return nil
}

View File

@@ -13,7 +13,7 @@ import (
// 返回值
// - 一个 gorm.DB 的指针
// - 一个清理所有数据库相关数据的函数
func GetDataBaseClient() (*gorm.DB, func(), error) {
func GetDataBaseClient() *gorm.DB {
dsn := "host=localhost " +
"user=gatekeeper " +
"dbname=crimson " +
@@ -25,28 +25,28 @@ func GetDataBaseClient() (*gorm.DB, func(), error) {
client, ero := gorm.Open(postgres.Open(dsn), &gorm.Config{})
if ero != nil {
fmt.Println("数据库链接建立失败")
return nil, nil, ero
panic(ero)
}
poolCfg, ero := client.DB()
if ero != nil {
fmt.Println("获取数据库链接池失败")
return nil, nil, ero
panic(ero)
}
cleanPoolCfg := func() {
ero := poolCfg.Close()
if ero != nil {
fmt.Println("清理过程中出现错误")
panic(ero)
}
}
//cleanPoolCfg := func() {
// ero := poolCfg.Close()
// if ero != nil {
// fmt.Println("清理过程中出现错误")
// panic(ero)
// }
//}
poolCfg.SetConnMaxIdleTime(3)
poolCfg.SetMaxOpenConns(10)
fmt.Println("构建数据库链接")
return client, cleanPoolCfg, nil
return client
}
func GetQuery(db *gorm.DB) *query.Query {

View File

@@ -0,0 +1,35 @@
package route
import (
"Crimson-Gatekeeper/internal/query"
"net/http"
"github.com/gin-gonic/gin"
)
type Controller interface {
register(gin *gin.Engine)
}
func RegCtrl(cs []Controller) {
route := gin.Default()
for _, ctrl := range cs {
ctrl.register(route)
}
http.Handle("/", route)
}
type TestBoot struct {
c *query.Query
}
func (t *TestBoot) Run() error {
http.HandleFunc("/echo", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello world!"))
})
return nil
}
func NewTestBoot(q *query.Query) *TestBoot {
return &TestBoot{q}
}