From a7664d5ed207847bc6898c59e1a3658f0f7489fb Mon Sep 17 00:00:00 2001 From: Rzy <465386466@qq.com> Date: Tue, 16 Jul 2024 18:54:13 +0800 Subject: [PATCH] =?UTF-8?q?=E9=92=88=E5=AF=B9=E9=82=AE=E4=B9=90=E7=9A=84?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/rpc/transfer.go | 2 +- env | 1 + sh/build_produce.sh | 2 +- sh/build_test.sh | 2 +- sh/depoly.sh | 2 +- until/env.go | 20 +++++++++++++++++--- 6 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 env diff --git a/cmd/rpc/transfer.go b/cmd/rpc/transfer.go index 116348b..0275c38 100644 --- a/cmd/rpc/transfer.go +++ b/cmd/rpc/transfer.go @@ -19,7 +19,7 @@ import ( "trasfer_middleware/until" ) -var configFile = flag.String("f", until.GetConfig(), "the config file") +var configFile = flag.String("f", fmt.Sprintf("%s%s", "../../config/", until.GetConfig()), "the config file") func main() { flag.Parse() diff --git a/env b/env new file mode 100644 index 0000000..c9e473a --- /dev/null +++ b/env @@ -0,0 +1 @@ +produce diff --git a/sh/build_produce.sh b/sh/build_produce.sh index 7cedbd8..1697f8c 100644 --- a/sh/build_produce.sh +++ b/sh/build_produce.sh @@ -3,7 +3,7 @@ . $(pwd)/sh/config.sh Environment="produce" ADDRESS="${PRODUCE_ADDRESS}" -echo "produce"> $(pwd)/sh/env +echo "produce"> $(pwd)/env . $(pwd)/sh/build.sh diff --git a/sh/build_test.sh b/sh/build_test.sh index ab72d0a..09bffe2 100644 --- a/sh/build_test.sh +++ b/sh/build_test.sh @@ -3,5 +3,5 @@ . $(pwd)/sh/config.sh Environment="test" ADDRESS="${TEST_ADDRESS}" -echo "test"> $(pwd)/sh/env +echo "test"> $(pwd)/env sh $(pwd)/sh/build.sh diff --git a/sh/depoly.sh b/sh/depoly.sh index 63c0c41..a939783 100755 --- a/sh/depoly.sh +++ b/sh/depoly.sh @@ -2,7 +2,7 @@ . $(pwd)/sh/config.sh -ENV=$(cat "$(pwd)/sh/env") +ENV=$(cat "$(pwd)/env") # 使用if-elif-else结构判断环境 if [ "$ENV"=="produce" ]; then ADDRESS="${PRODUCE_ADDRESS}" diff --git a/until/env.go b/until/env.go index 2a6526b..8472967 100644 --- a/until/env.go +++ b/until/env.go @@ -1,8 +1,22 @@ package until -import "os" +import ( + "fmt" + "os" +) func GetConfig() string { - - return os.Getenv("GO_ENV") + var dir string + pwd, _ := os.Getwd() + path := fmt.Sprintf("%s%s", pwd, "/../../env") + bytes, _ := os.ReadFile(path) + switch string(bytes) { + case "produce": + dir = "produce.yaml" + case "test": + dir = "test.yaml" + default: + dir = "local.yaml" + } + return dir }