Skip to content

Commit

Permalink
add marshal functions
Browse files Browse the repository at this point in the history
Signed-off-by: MUzairS15 <muzair.shaikh810@gmail.com>
  • Loading branch information
MUzairS15 committed Aug 16, 2024
1 parent d5bd691 commit 85c93d6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions encoding/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package encoding
import (
"encoding/json"

"github.com/layer5io/meshkit/utils"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -49,3 +50,15 @@ func unmarshalJSON(data []byte, result interface{}) error {
}
return nil
}

func Marshal(in interface{}) ([]byte, error) {
result, err := json.Marshal(in)
if err != nil {
result, err = yaml.Marshal(in)
if err != nil {
return nil, utils.ErrMarshal(err)
}
}

return result, nil
}

0 comments on commit 85c93d6

Please sign in to comment.