diff --git a/json_utility.go b/json_utility.go index 844a4fc..6f82409 100644 --- a/json_utility.go +++ b/json_utility.go @@ -105,6 +105,23 @@ func NewPayload(r *http.Request, table string) Payload { return pload } +// MakePayload returs a payload for provided table with populated Data field. +func MakePayload(r *http.Request, table string, data interface{}) Payload { + var pload Payload + + //pload.Method = r.Method + " " + r.URL.Path + pload.Method = r.Method + " " + r.RequestURI + if table != "" { + pload.Params = make(map[string]string, 0) + pload.Lang = translations(table) + pload.Fields = fields(table) + pload.IdField = id(table) + pload.Correlations = correlations(table) + } + pload.Data = data + return pload +} + // DeliverPayload encodes payload to w. func DeliverPayload(w http.ResponseWriter, payload Payload) { json.NewEncoder(w).Encode(payload)