Skip to content

Commit 4c4e09d

Browse files
committed
fix: yaml reading with "---"
Signed-off-by: Bird <aflybird0@gmail.com>
1 parent 26f543d commit 4c4e09d

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

internal/pkg/configmanager/manager.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package configmanager
22

33
import (
4+
"bytes"
45
"errors"
56
"fmt"
67
"io"
@@ -32,6 +33,9 @@ func (m *Manager) LoadConfig() (*Config, error) {
3233
if err != nil {
3334
return nil, err
3435
}
36+
// replace all "---"
37+
// otherwise yaml.Unmarshal can only read the content before the first "---"
38+
configBytesOrigin = bytes.Replace(configBytesOrigin, []byte("---"), []byte("\n"), -1)
3539

3640
// 2. get all globals vars
3741
globalVars, err := getVarsFromConfigBytes(configBytesOrigin)
@@ -40,7 +44,7 @@ func (m *Manager) LoadConfig() (*Config, error) {
4044
}
4145

4246
// 3. yaml unmarshal to get the whole config
43-
var config ConfigRaw
47+
config := ConfigRaw{}
4448
err = yaml.Unmarshal(configBytesOrigin, &config)
4549
if err != nil {
4650
log.Errorf("Please verify the format of your config. Error: %s.", err)
@@ -186,7 +190,7 @@ func (m *Manager) getWholeConfigBytes() ([]byte, error) {
186190
}
187191

188192
configBytesStr := string(configBytes)
189-
log.Debugf("The final whole config is: \n%s\n", configBytesStr)
193+
log.Debugf("The whole config without rendered is: \n%s\n", configBytesStr)
190194

191195
return configBytes, nil
192196
}

0 commit comments

Comments
 (0)