go-waku/mobile/response.go
Richard Ramos f1f6cb04f0
feat: kotlin android example (#226)
* feat: kotlin android example
* Adding lightpush and store to kotlin example
2022-04-12 08:12:14 -04:00

42 lines
771 B
Go

package gowaku
import "encoding/json"
type jsonResponse struct {
Error *string `json:"error,omitempty"`
Result interface{} `json:"result"`
}
func prepareJSONResponse(result interface{}, err error) string {
if err != nil {
errStr := err.Error()
errResponse := jsonResponse{
Error: &errStr,
}
response, _ := json.Marshal(&errResponse)
return string(response)
}
data, err := json.Marshal(jsonResponse{Result: result})
if err != nil {
return prepareJSONResponse(nil, err)
}
return string(data)
}
func makeJSONResponse(err error) string {
var errString *string = nil
if err != nil {
errStr := err.Error()
errString = &errStr
}
out := jsonResponse{
Error: errString,
}
outBytes, _ := json.Marshal(out)
return string(outBytes)
}