12345678910111213141516171819202122232425262728 |
- package client
- import (
- "encoding/json"
- "github.com/pkg/errors"
- "gopkg.in/yaml.v3"
- )
- func unmarshalYamlToJsonStruct(yamlBytes []byte, output any) error {
- yamlMap := make(map[string]any)
- err := yaml.Unmarshal(yamlBytes, &yamlMap)
- if err != nil {
- return errors.New(err.Error())
- }
- jsonBytes, err := json.Marshal(yamlMap)
- if err != nil {
- return errors.New(err.Error())
- }
- err = json.Unmarshal(jsonBytes, output)
- if err != nil {
- return errors.New(err.Error())
- }
- return nil
- }
|