import ( "encoding/json" "github.com/ninnemana/api/helpers/encoding" ) data := map[string]string{ "name": "John Smith", "age": "35", } jsonData, err := json.Marshal(data) if err != nil { // handle error } encodedData, err := encoding.EncodeJSON(jsonData) if err != nil { // handle error }
import ( "encoding/xml" "github.com/ninnemana/api/helpers/encoding" ) type Person struct { Name string `xml:"name"` Age int `xml:"age"` } person := &Person{ Name: "John Smith", Age: 35, } xmlData, err := xml.Marshal(person) if err != nil { // handle error } encodedData, err := encoding.EncodeXML(xmlData) if err != nil { // handle error }These examples demonstrate how the Encoder can be used to encode data in JSON or XML format.