forked from k3d-io/k3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: replace gopkg.in/yaml.v2 with sigs.k8s.io/yaml
k3d-io#1094 (comment) Signed-off-by: Sunghoon Kang <[email protected]>
- Loading branch information
Sunghoon Kang
committed
Jul 1, 2022
1 parent
2fc798f
commit 48221ce
Showing
15 changed files
with
161 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package util | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
|
||
goyaml "gopkg.in/yaml.v2" | ||
"sigs.k8s.io/yaml" | ||
) | ||
|
||
func SplitYAML(resources []byte) ([][]byte, error) { | ||
dec := goyaml.NewDecoder(bytes.NewReader(resources)) | ||
|
||
var res [][]byte | ||
for { | ||
var value interface{} | ||
err := dec.Decode(&value) | ||
if err == io.EOF { | ||
break | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
valueBytes, err := yaml.Marshal(value) | ||
if err != nil { | ||
return nil, err | ||
} | ||
res = append(res, valueBytes) | ||
} | ||
return res, nil | ||
} | ||
|
||
type YAMLEncoder struct { | ||
encoder *goyaml.Encoder | ||
} | ||
|
||
func NewYAMLEncoder(w io.Writer) *YAMLEncoder { | ||
return &YAMLEncoder{ | ||
encoder: goyaml.NewEncoder(w), | ||
} | ||
} | ||
|
||
func (e *YAMLEncoder) Encode(v interface{}) (err error) { | ||
data, err := yaml.Marshal(v) | ||
if err != nil { | ||
return err | ||
} | ||
var doc interface{} | ||
if err := yaml.Unmarshal(data, &doc); err != nil { | ||
return err | ||
} | ||
return e.encoder.Encode(doc) | ||
} | ||
|
||
func (e *YAMLEncoder) Close() (err error) { | ||
return e.encoder.Close() | ||
} |
Oops, something went wrong.