-
Notifications
You must be signed in to change notification settings - Fork 52
/
dml.go
43 lines (35 loc) · 975 Bytes
/
dml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package sqlcore
import (
"encoding/json"
"io"
"net/http"
)
// Run all DML queries
func DML(sqlText, originApp string, biscuitArray []string, resources []string) (errMsg string, status bool) {
request, err := createDataModificationRequest(sqlText, originApp, biscuitArray, resources)
if err != nil {
return err.Error(), false
}
client := http.Client{}
response, err := client.Do(request)
if err != nil {
return err.Error(), false
}
defer response.Body.Close()
body, err := io.ReadAll(response.Body)
if err != nil {
return err.Error(), false
}
if response.StatusCode != 200 {
return string(body), false
}
return "", true
}
func createDataModificationRequest(sqlText, originApp string, biscuitArray, resources []string) (request *http.Request, err error) {
postBody, _ := json.Marshal(map[string]interface{}{
"biscuits": biscuitArray,
"resources": resources,
"sqlText": sqlText,
})
return createRequest("dml", originApp, postBody)
}