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 }