Skip to content

Commit

Permalink
Merge pull request #564 from MUzairS15/MUzairS15/encoding
Browse files Browse the repository at this point in the history
Add `Marshal` function for encoding package.
  • Loading branch information
Mohd Uzair authored Aug 16, 2024
2 parents 6bec777 + d648931 commit 1d5d3f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 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
}
2 changes: 0 additions & 2 deletions models/meshmodel/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,11 @@ func (rm *RegistryManager) Cleanup() {
func (rm *RegistryManager) RegisterEntity(h connection.Connection, en entity.Entity) (bool, bool, error) {
registrantID, err := h.Create(rm.db)
if err != nil {
fmt.Println("REGISTRANT ERROR ")
return true, false, err
}

entityID, err := en.Create(rm.db, registrantID)
if err != nil {
fmt.Println("COMP ERROR ")
return false, true, err
}
id, _ := uuid.NewV4()
Expand Down

0 comments on commit 1d5d3f9

Please sign in to comment.