mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-17 05:18:04 +00:00
26 lines
356 B
Go
26 lines
356 B
Go
|
package common
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"gopkg.in/yaml.v3"
|
||
|
)
|
||
|
|
||
|
func MarshalYAML(sth interface{}) []byte {
|
||
|
if sth == nil {
|
||
|
return nil
|
||
|
}
|
||
|
buf := new(bytes.Buffer)
|
||
|
encoder := yaml.NewEncoder(buf)
|
||
|
|
||
|
defer func() {
|
||
|
encoder.Close()
|
||
|
buf.Truncate(0)
|
||
|
}()
|
||
|
|
||
|
encoder.SetIndent(2)
|
||
|
if err := encoder.Encode(sth); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
return buf.Bytes()
|
||
|
}
|