feat: router run with PreRun

This commit is contained in:
Young Xu 2023-03-19 22:24:12 +08:00
parent b2ad24762a
commit 7336d0d9d2
Signed by: xuthus5
GPG Key ID: A23CF9620CBB55F9
2 changed files with 13 additions and 0 deletions

View File

@ -136,6 +136,14 @@ func (r *Register) RegisterStruct(routers *Routers, drv interface{}, mws ...gin.
}
}
// PreRun 运行前动作
func (r *Register) PreRun(f func() error) error {
if f == nil {
return nil
}
return f()
}
// Run 服务运行
func (r *Register) Run() {
if r.addr == "" {

View File

@ -28,6 +28,11 @@ func TestRegister_getCallFunc(t *testing.T) {
func TestNewRegister(t *testing.T) {
var reg = NewRegister()
reg.DefaultRouter(WithGinMode(gin.DebugMode))
if err := reg.PreRun(func() error {
return nil
}); err != nil {
// todo
}
// protoc core/file_module.proto --coco_out=core --go_out=core
//reg.RegisterStruct(AutoGenFileRouterMap, &File{})
reg.Run()