From e31b77a32ae25dbec09f5572698342dfc7001aff Mon Sep 17 00:00:00 2001 From: maxzhang Date: Thu, 26 Dec 2019 20:51:35 +0800 Subject: [PATCH 1/2] IServer graceful exit --- Framework/FastHttpServer.go | 2 +- Framework/HttpServer.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Framework/FastHttpServer.go b/Framework/FastHttpServer.go index e0a3b67a..430c3b80 100644 --- a/Framework/FastHttpServer.go +++ b/Framework/FastHttpServer.go @@ -37,7 +37,7 @@ func (server FastHttpServer) Run(context *HostBuildContext) (e error) { // 创建系统信号接收器 quit := make(chan os.Signal) - signal.Notify(quit, os.Interrupt) + signal.Notify(quit, os.Interrupt, os.Kill) go func() { <-quit context.ApplicationCycle.StopApplication() diff --git a/Framework/HttpServer.go b/Framework/HttpServer.go index 2c3dc71f..80cb9a79 100644 --- a/Framework/HttpServer.go +++ b/Framework/HttpServer.go @@ -38,7 +38,7 @@ func (server HttpServer) Run(context *HostBuildContext) (e error) { } // 创建系统信号接收器 quit := make(chan os.Signal) - signal.Notify(quit, os.Interrupt) + signal.Notify(quit, os.Interrupt, os.Kill) go func() { <-quit context.ApplicationCycle.StopApplication() From a4f2d51c84dad7565e9c8dba2644bf94b5682328 Mon Sep 17 00:00:00 2001 From: maxzhang1985 Date: Wed, 1 Jan 2020 13:23:38 +0800 Subject: [PATCH 2/2] the mvc route , request is not must be "controller" words end. --- Examples/SimpleWeb/contollers/usercontroller.go | 13 ++++++++----- Examples/SimpleWeb/main.go | 1 - Framework/Version.go | 2 +- Router/MvcRouterHandler.go | 3 +++ 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Examples/SimpleWeb/contollers/usercontroller.go b/Examples/SimpleWeb/contollers/usercontroller.go index 7e7319b4..b3e8fb31 100644 --- a/Examples/SimpleWeb/contollers/usercontroller.go +++ b/Examples/SimpleWeb/contollers/usercontroller.go @@ -4,14 +4,16 @@ import ( "github.com/maxzhang1985/yoyogo/ActionResult" "github.com/maxzhang1985/yoyogo/Context" "github.com/maxzhang1985/yoyogo/Controller" + "github.com/maxzhang1985/yoyogo/Examples/SimpleWeb/models" ) type UserController struct { *Controller.ApiController + userAction models.IUserAction } -func NewUserController() *UserController { - return &UserController{} +func NewUserController(userAction models.IUserAction) *UserController { + return &UserController{userAction: userAction} } type RegiserRequest struct { @@ -20,12 +22,13 @@ type RegiserRequest struct { Password string `param:"password"` } -func (p *UserController) Register(ctx *Context.HttpContext, request *RegiserRequest) ActionResult.IActionResult { +func (this *UserController) Register(ctx *Context.HttpContext, request *RegiserRequest) ActionResult.IActionResult { result := Controller.ApiResult{Success: true, Message: "ok", Data: request} return ActionResult.Json{Data: result} } -func (p *UserController) GetInfo() Controller.ApiResult { - return Controller.ApiResult{Success: true, Message: "ok"} +func (this *UserController) GetInfo() Controller.ApiResult { + + return this.OK(this.userAction.Login("zhang")) } diff --git a/Examples/SimpleWeb/main.go b/Examples/SimpleWeb/main.go index 51caf04e..994d4390 100644 --- a/Examples/SimpleWeb/main.go +++ b/Examples/SimpleWeb/main.go @@ -33,7 +33,6 @@ func CreateCustomBuilder() *YoyoGo.HostBuilder { builder.AddController(contollers.NewUserController) }). ConfigureServices(func(serviceCollection *DependencyInjection.ServiceCollection) { - //serviceCollection.AddSingletonByNameAndImplements("usercontroller", contollers.NewUserController, new(Controller.IController)) serviceCollection.AddTransientByImplements(models.NewUserAction, new(models.IUserAction)) }). OnApplicationLifeEvent(getApplicationLifeEvent) diff --git a/Framework/Version.go b/Framework/Version.go index b5778bc0..80604f01 100644 --- a/Framework/Version.go +++ b/Framework/Version.go @@ -1,5 +1,5 @@ package YoyoGo const ( - Version = "v1.4.6" + Version = "v1.4.8" ) diff --git a/Router/MvcRouterHandler.go b/Router/MvcRouterHandler.go index b3ae45ff..6bc9ea13 100644 --- a/Router/MvcRouterHandler.go +++ b/Router/MvcRouterHandler.go @@ -16,6 +16,9 @@ func (handler *MvcRouterHandler) Invoke(ctx *Context.HttpContext, pathComponents return nil } controllerName := strings.ToLower(pathComponents[0]) + if !strings.Contains(controllerName, "controller") { + controllerName += "controller" + } actionName := pathComponents[1] controller := Controller.ActivateController(ctx.RequiredServices, controllerName)