From 0c52d7717588af263146a6fb62038f1e834a5e98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Tikvi=C4=87?= Date: Fri, 10 Nov 2017 13:33:38 +0100 Subject: [PATCH] make payload with provided data --- json_utility.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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) -- 1.8.1.2