Commit 66478e04fb0d28d69edb9df67bd3379e6da1f061
1 parent
0c52d77175
Exists in
master
and in
1 other branch
payload now returns type
Showing
1 changed file
with
9 additions
and
22 deletions
Show diff stats
json_utility.go
... | ... | @@ -3,6 +3,7 @@ package webutility |
3 | 3 | import ( |
4 | 4 | "encoding/json" |
5 | 5 | "errors" |
6 | + "fmt" | |
6 | 7 | "io" |
7 | 8 | "net/http" |
8 | 9 | "sync" |
... | ... | @@ -11,7 +12,7 @@ import ( |
11 | 12 | ) |
12 | 13 | |
13 | 14 | var mu = &sync.Mutex{} |
14 | -var payloads []payloadBuff | |
15 | +var payloads []Payload | |
15 | 16 | |
16 | 17 | type LangMap map[string]map[string]string |
17 | 18 | |
... | ... | @@ -33,20 +34,8 @@ type Translation struct { |
33 | 34 | FieldsLabels map[string]string `json:"fieldsLabels"` |
34 | 35 | } |
35 | 36 | |
36 | -type payloadBuff struct { | |
37 | - Type string `json:"tableType"` | |
38 | - Method string `json:"method"` | |
39 | - Params map[string]string `json:"params"` | |
40 | - Lang []Translation `json:"lang"` | |
41 | - Fields []Field `json:"fields"` | |
42 | - Correlations []CorrelationField `json:"correlationFields"` | |
43 | - IdField string `json:"idField"` | |
44 | - | |
45 | - // Data can only hold slices of any type. It can't be used for itteration | |
46 | - Data interface{} `json:"data"` | |
47 | -} | |
48 | - | |
49 | 37 | type Payload struct { |
38 | + Type string `json:"type"` | |
50 | 39 | Method string `json:"method"` |
51 | 40 | Params map[string]string `json:"params"` |
52 | 41 | Lang []Translation `json:"lang"` |
... | ... | @@ -54,8 +43,7 @@ type Payload struct { |
54 | 43 | Correlations []CorrelationField `json:"correlationFields"` |
55 | 44 | IdField string `json:"idField"` |
56 | 45 | |
57 | - // Data contains JSON payload. | |
58 | - // It can't be used for itteration | |
46 | + // Data holds JSON payload. It can't be used for itteration. | |
59 | 47 | Data interface{} `json:"data"` |
60 | 48 | } |
61 | 49 | |
... | ... | @@ -79,7 +67,7 @@ func InitTables(db *ora.Ses, project string) error { |
79 | 67 | // ReloadTables reloads all payloads in the payloads variable. |
80 | 68 | // Returns an error if it fails. |
81 | 69 | func ReloadTables(db *ora.Ses, project string) error { |
82 | - payloads = make([]payloadBuff, 0) | |
70 | + payloads = make([]Payload, 0) | |
83 | 71 | return InitTables(db, project) |
84 | 72 | } |
85 | 73 | |
... | ... | @@ -93,8 +81,8 @@ func DecodeJSON(r io.Reader, v interface{}) error { |
93 | 81 | func NewPayload(r *http.Request, table string) Payload { |
94 | 82 | var pload Payload |
95 | 83 | |
96 | - //pload.Method = r.Method + " " + r.URL.Path | |
97 | 84 | pload.Method = r.Method + " " + r.RequestURI |
85 | + pload.Type = table | |
98 | 86 | if table != "" { |
99 | 87 | pload.Params = make(map[string]string, 0) |
100 | 88 | pload.Lang = translations(table) |
... | ... | @@ -105,11 +93,10 @@ func NewPayload(r *http.Request, table string) Payload { |
105 | 93 | return pload |
106 | 94 | } |
107 | 95 | |
108 | -// MakePayload returs a payload for provided table with populated Data field. | |
109 | -func MakePayload(r *http.Request, table string, data interface{}) Payload { | |
96 | +// BuildPayload returs a payload for provided table with populated Data field. | |
97 | +func BuildPayload(r *http.Request, table string, data interface{}) Payload { | |
110 | 98 | var pload Payload |
111 | 99 | |
112 | - //pload.Method = r.Method + " " + r.URL.Path | |
113 | 100 | pload.Method = r.Method + " " + r.RequestURI |
114 | 101 | if table != "" { |
115 | 102 | pload.Params = make(map[string]string, 0) |
... | ... | @@ -190,7 +177,7 @@ func correlations(ptype string) []CorrelationField { |
190 | 177 | // Returns an error if it fails. |
191 | 178 | func fetchJSON(db *ora.Ses, project string) ([]byte, error) { |
192 | 179 | db.SetCfg(db.Cfg().SetClob(ora.S)) |
193 | - stmt, err := db.Prep(`SELECT JSON_NCLOB FROM TABLES_CONFIG WHERE PROJEKAT`+EqualQuotes(project), ora.S) | |
180 | + stmt, err := db.Prep(`SELECT JSON_NCLOB FROM TABLES_CONFIG WHERE PROJEKAT = `+fmt.Sprintf("'%s'", project), ora.S) | |
194 | 181 | defer stmt.Close() |
195 | 182 | if err != nil { |
196 | 183 | return nil, err | ... | ... |