-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebServer.go
65 lines (59 loc) · 1.49 KB
/
webServer.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package main
import (
"fmt"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
)
type httpresponse struct {
Status bool
Message string
}
func Validate(log bson.M) error {
if val, ok := log["Team"]; !ok || val == "" {
return fmt.Errorf("cannot find Team property or value")
}
if val, ok := log["Log"]; !ok || val == "" {
return fmt.Errorf("cannot find Log property or value")
}
if val, ok := log["Severity"]; !ok || val == "" {
return fmt.Errorf("cannot find Severity property or value")
}
return nil
}
func AddMessage(log bson.M) error {
QConnectionString = GlobalConfig.QConfig[0].QConnectionString
QName = GlobalConfig.QConfig[0].QName
err := Brkr.Do(log)
if err != nil {
QConnectionString = GlobalConfig.QConfig[1].QConnectionString
QName = GlobalConfig.QConfig[1].QName
err := FM.MessageAdd(log)
if err != nil {
return err
}
}
return nil
}
func AddLog(c *gin.Context) {
message := "Success"
log := bson.M{}
err := c.BindJSON(&log)
if err != nil {
message = fmt.Sprintf("Error: %s", err)
c.IndentedJSON(400, httpresponse{Status: false, Message: message})
return
}
err = Validate(log)
if err != nil {
message = fmt.Sprintf("Error: %s", err)
c.IndentedJSON(400, httpresponse{Status: false, Message: message})
return
}
err = AddMessage(log)
if err != nil {
message = fmt.Sprintf("Error: %s", err)
c.IndentedJSON(400, httpresponse{Status: false, Message: message})
return
}
c.IndentedJSON(200, httpresponse{Status: true, Message: message})
}