Skip to content

Commit

Permalink
框架集成Config
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyofx committed Aug 12, 2020
1 parent 5bca353 commit 6f26d98
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
18 changes: 10 additions & 8 deletions Abstractions/HostBuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}

Expand Down
12 changes: 8 additions & 4 deletions WebFramework/Middleware/StaticMiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
7 changes: 6 additions & 1 deletion WebFramework/WebHostBuilderDecorator.go
Original file line number Diff line number Diff line change
@@ -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 {
}
Expand Down Expand Up @@ -31,6 +34,8 @@ func (decorator WebHostBuilderDecorator) OverrideNewHost(server Abstractions.ISe
server = DefaultHttpServer(address)
}
}
} else {
server = NewFastHttp(YoyoGo.DefaultAddress)
}
return NewWebHost(server, context)
}
Expand Down

0 comments on commit 6f26d98

Please sign in to comment.