添加多环境配置

This commit is contained in:
lzh 2025-06-06 10:49:52 +08:00
parent b81011d362
commit a8a95ad253
4 changed files with 38 additions and 1 deletions

View File

@ -1,6 +1,7 @@
package main package main
import ( import (
"fmt"
"log" "log"
"os" "os"
"os/signal" "os/signal"
@ -13,7 +14,7 @@ import (
) )
func main() { func main() {
os.Setenv(constant.ConfigFileEnvKey, "../conf/dubbogo.yaml") initEnv()
config.SetProviderService(&service.FilesProvider{}) config.SetProviderService(&service.FilesProvider{})
if err := config.Load(); err != nil { if err := config.Load(); err != nil {
panic(err) panic(err)
@ -24,3 +25,11 @@ func main() {
log.Printf("Caught signal %s: shutting down.", sig) log.Printf("Caught signal %s: shutting down.", sig)
os.Exit(0) os.Exit(0)
} }
func initEnv() {
if os.Getenv("MODE_ENV") != "" {
os.Setenv(constant.ConfigFileEnvKey, fmt.Sprintf("./conf/%s/%s", os.Getenv("MODE_ENV"), "dubbogo.yaml"))
} else {
os.Setenv(constant.ConfigFileEnvKey, "../conf/dubbogo.yaml")
}
}

View File

14
conf/dev/dubbogo.yaml Normal file
View File

@ -0,0 +1,14 @@
dubbo:
registries:
demoZK:
protocol: zookeeper
address: 172.16.100.93:2181
protocols:
triple:
name: tri
port: 20027
provider:
services:
FileProvider:
protocol: tri
interface: files.File # must be compatible with grpc or dubbo-java

14
conf/prod/dubbogo.yaml Normal file
View File

@ -0,0 +1,14 @@
dubbo:
registries:
demoZK:
protocol: zookeeper
address: zookeeper:2181
protocols:
triple:
name: tri
port: 20027
provider:
services:
FileProvider:
protocol: tri
interface: files.File # must be compatible with grpc or dubbo-java