Skip to content

Commit

Permalink
fix: empty config
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangliang committed Mar 8, 2022
1 parent 090d4d8 commit 8db206a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion examples/hello/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func HelloD(tick agent.Ticker) (behavior3go.Status, error) {
}

func HelloE(tick agent.Ticker) (behavior3go.Status, error) {
return behavior3go.FAILURE, fmt.Errorf("test error essage.##")
return behavior3go.FAILURE, fmt.Errorf("test error essage.#123456789#")
// return behavior3go.SUCCESS, nil
}

Expand Down
12 changes: 11 additions & 1 deletion pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package agent
import (
"context"
"net/http"
"os"
"strconv"
"strings"

"github.com/LilithGames/agent-go/tools/metric"
"github.com/spf13/viper"
Expand Down Expand Up @@ -35,7 +37,15 @@ func NewAgent(engine *Engine, cfg *viper.Viper, opts ...Option) *Agent {
log.Panic("absent plans")
}
if cfg == nil {
cfg = viper.New()
cfg := viper.New()
cfg.SetConfigType("prop")
envs := os.Environ()
for _, env := range envs {
parts := strings.SplitN(env, "=", 2)
if len(parts) == 2 {
cfg.Set(parts[0], parts[1])
}
}
}
id := cfg.GetString("ID")
endpoint := cfg.GetString(masterAddr)
Expand Down

0 comments on commit 8db206a

Please sign in to comment.