Skip to content

Commit

Permalink
添加本地配置对象
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyofx committed Dec 30, 2021
1 parent d6ed0ce commit 0843458
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
8 changes: 4 additions & 4 deletions examples/simpleweb/config_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ yoyogo:
strategy: "round-robin" # round-robin , weight-time , random
type: "nacos"
metadata:
url: "nacos.yoyogo.run"
port: 80
url: "47.100.213.49"
port: 8848
namespace: "public"
group: "DEFAULT_GROUP"
cluster: ""
configserver:
dataId: "simple_demo"
auth:
enable: true
enable: false
username: "nacos"
password: "nacos"
password: "P@ssW0rd"
endpoint: ""
regionId: ""
accessKey: ""
Expand Down
15 changes: 12 additions & 3 deletions examples/simpleweb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/yoyofx/yoyogo/abstractions"
"github.com/yoyofx/yoyogo/abstractions/xlog"
"github.com/yoyofx/yoyogo/pkg/configuration"
nacosconfig "github.com/yoyofx/yoyogo/pkg/configuration/nacos"
_ "github.com/yoyofx/yoyogo/pkg/datasources/mysql"
_ "github.com/yoyofx/yoyogo/pkg/datasources/redis"
"github.com/yoyofx/yoyogo/pkg/servicediscovery/nacos"
Expand Down Expand Up @@ -45,8 +44,18 @@ func main() {

//* Create the builder of Web host
func CreateCustomBuilder() *abstractions.HostBuilder {
config := nacosconfig.RemoteConfig("config")
//config := apollo.RemoteConfig("config")
// local away:
// config := abstractions.NewConfigurationBuilder().
// AddEnvironment().
// AddYamlFile("config").Build()
// remote away:
// -- github.com/yoyofx/yoyogo/pkg/configuration/nacos
// -- github.com/yoyofx/yoyogo/pkg/configuration/apollo
// config := nacosconfig.RemoteConfig("config")
// config := apollo.RemoteConfig("config")

config := configuration.LocalConfig("config")

return web.NewWebHostBuilder().
UseConfiguration(config).
Configure(func(app *web.ApplicationBuilder) {
Expand Down
7 changes: 7 additions & 0 deletions pkg/configuration/localconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package configuration

import "github.com/yoyofx/yoyogo/abstractions"

func LocalConfig(configPath string) *abstractions.Configuration {
return abstractions.NewConfigurationBuilder().AddEnvironment().AddYamlFile(configPath).Build()
}

0 comments on commit 0843458

Please sign in to comment.