From 6f26d98875ec79c6b324af6692178e35ca58580e Mon Sep 17 00:00:00 2001 From: yoyofx Date: Wed, 12 Aug 2020 12:21:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A1=86=E6=9E=B6=E9=9B=86=E6=88=90Config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Abstractions/HostBuilder.go | 18 ++++++++++-------- WebFramework/Middleware/StaticMiddleware.go | 12 ++++++++---- WebFramework/WebHostBuilderDecorator.go | 7 ++++++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/Abstractions/HostBuilder.go b/Abstractions/HostBuilder.go index 1a887414..a65fde46 100644 --- a/Abstractions/HostBuilder.go +++ b/Abstractions/HostBuilder.go @@ -91,22 +91,24 @@ func RunningHostEnvironmentSetting(hostEnv *Context.HostEnvironment) { func buildingHostEnvironmentSetting(context *HostBuildContext) { hostEnv := context.HostingEnvironment hostEnv.Version = YoyoGo.Version + hostEnv.Addr = DetectAddress("") config := context.HostConfiguration - hostEnv.ApplicationName = config.Name - if config.Server.Address != "" { - hostEnv.Addr = config.Server.Address - } else { - hostEnv.Addr = DetectAddress("") + if config != nil { + hostEnv.ApplicationName = config.Name + if config.Server.Address != "" { + hostEnv.Addr = config.Server.Address + } + if config.Profile != "" { + hostEnv.Profile = config.Profile + } } + hostEnv.Port = strings.Replace(hostEnv.Addr, ":", "", -1) hostEnv.Args = os.Args if hostEnv.Profile == "" { hostEnv.Profile = Context.Dev } - if config.Profile != "" { - hostEnv.Profile = config.Profile - } } diff --git a/WebFramework/Middleware/StaticMiddleware.go b/WebFramework/Middleware/StaticMiddleware.go index 013f7721..c76e354a 100644 --- a/WebFramework/Middleware/StaticMiddleware.go +++ b/WebFramework/Middleware/StaticMiddleware.go @@ -32,10 +32,14 @@ func NewStatic(patten string, path string) *Static { } func NewStaticWithConfig(configuration Abstractions.IConfiguration) *Static { - config := configuration.GetSection("application.server.static") - patten := config.Get("patten").(string) - path := config.Get("webroot").(string) - return NewStatic(patten, path) + if configuration != nil { + config := configuration.GetSection("application.server.static") + patten := config.Get("patten").(string) + path := config.Get("webroot").(string) + return NewStatic(patten, path) + } else { + return NewStatic("/", "./Static") + } } func (s *Static) Inovke(ctx *Context.HttpContext, next func(ctx *Context.HttpContext)) { diff --git a/WebFramework/WebHostBuilderDecorator.go b/WebFramework/WebHostBuilderDecorator.go index 4a74b07d..5ed28157 100644 --- a/WebFramework/WebHostBuilderDecorator.go +++ b/WebFramework/WebHostBuilderDecorator.go @@ -1,6 +1,9 @@ package YoyoGo -import "github.com/yoyofx/yoyogo/Abstractions" +import ( + YoyoGo "github.com/yoyofx/yoyogo" + "github.com/yoyofx/yoyogo/Abstractions" +) type WebHostBuilderDecorator struct { } @@ -31,6 +34,8 @@ func (decorator WebHostBuilderDecorator) OverrideNewHost(server Abstractions.ISe server = DefaultHttpServer(address) } } + } else { + server = NewFastHttp(YoyoGo.DefaultAddress) } return NewWebHost(server, context) }