Commit 0c52d7717588af263146a6fb62038f1e834a5e98
1 parent
8bec68a1e8
Exists in
master
and in
1 other branch
make payload with provided data
Showing
1 changed file
with
17 additions
and
0 deletions
Show diff stats
json_utility.go
... | ... | @@ -105,6 +105,23 @@ func NewPayload(r *http.Request, table string) Payload { |
105 | 105 | return pload |
106 | 106 | } |
107 | 107 | |
108 | +// MakePayload returs a payload for provided table with populated Data field. | |
109 | +func MakePayload(r *http.Request, table string, data interface{}) Payload { | |
110 | + var pload Payload | |
111 | + | |
112 | + //pload.Method = r.Method + " " + r.URL.Path | |
113 | + pload.Method = r.Method + " " + r.RequestURI | |
114 | + if table != "" { | |
115 | + pload.Params = make(map[string]string, 0) | |
116 | + pload.Lang = translations(table) | |
117 | + pload.Fields = fields(table) | |
118 | + pload.IdField = id(table) | |
119 | + pload.Correlations = correlations(table) | |
120 | + } | |
121 | + pload.Data = data | |
122 | + return pload | |
123 | +} | |
124 | + | |
108 | 125 | // DeliverPayload encodes payload to w. |
109 | 126 | func DeliverPayload(w http.ResponseWriter, payload Payload) { |
110 | 127 | json.NewEncoder(w).Encode(payload) | ... | ... |