Merge pull request #683 from trheyi/main
refactor: Replace $ENV with os.Getenv in loadApp function
This commit is contained in:
commit
94ca83a1e9
1 changed files with 11 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ package engine
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
|
|
@ -41,6 +42,7 @@ import (
|
||||||
|
|
||||||
// LoadHooks used to load custom widgets/processes
|
// LoadHooks used to load custom widgets/processes
|
||||||
var LoadHooks = map[string]func(config.Config) error{}
|
var LoadHooks = map[string]func(config.Config) error{}
|
||||||
|
var envRe = regexp.MustCompile(`\$ENV\.([0-9a-zA-Z_-]+)`)
|
||||||
|
|
||||||
// RegisterLoadHook register custom load hook
|
// RegisterLoadHook register custom load hook
|
||||||
func RegisterLoadHook(name string, hook func(config.Config) error) error {
|
func RegisterLoadHook(name string, hook func(config.Config) error) error {
|
||||||
|
|
@ -543,6 +545,15 @@ func loadApp(root string) error {
|
||||||
return fmt.Errorf("app.yao or app.jsonc or app.json does not exists")
|
return fmt.Errorf("app.yao or app.jsonc or app.json does not exists")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace $ENV with os.Getenv
|
||||||
|
appData = envRe.ReplaceAllFunc(appData, func(s []byte) []byte {
|
||||||
|
key := string(s[5:])
|
||||||
|
val := os.Getenv(key)
|
||||||
|
if val == "" {
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
return []byte(val)
|
||||||
|
})
|
||||||
share.App = share.AppInfo{}
|
share.App = share.AppInfo{}
|
||||||
return application.Parse(appFile, appData, &share.App)
|
return application.Parse(appFile, appData, &share.App)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue