Skip to content

Commit

Permalink
refactor: Replace $ENV with os.Getenv in loadApp function
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Jul 15, 2024
1 parent 931394b commit 097bf45
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions engine/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package engine
import (
"fmt"
"os"
"regexp"
"strings"

"github.com/fatih/color"
Expand Down Expand Up @@ -41,6 +42,7 @@ import (

// LoadHooks used to load custom widgets/processes
var LoadHooks = map[string]func(config.Config) error{}
var envRe = regexp.MustCompile(`\$ENV\.([0-9a-zA-Z_-]+)`)

// RegisterLoadHook register custom load hook
func RegisterLoadHook(name string, hook func(config.Config) error) error {
Expand Down Expand Up @@ -543,6 +545,15 @@ func loadApp(root string) error {
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{}
return application.Parse(appFile, appData, &share.App)
}
Expand Down

0 comments on commit 097bf45

Please sign in to comment.