check record request and response to main route
This commit is contained in:
parent
922841ecd1
commit
af9d0eb6a5
BIN
APIServer.exe
BIN
APIServer.exe
Binary file not shown.
14
APIServer.go
14
APIServer.go
@ -368,8 +368,15 @@ func handleSetUutInfo(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if cfg.Settings.LogRequest {
|
||||
logger.Printf("[MSG] %s; %s; Request: %#v\r\n", addr, uri, params)
|
||||
}
|
||||
ews := new(ews.EWS)
|
||||
rst = ews.SetUutInfo(cfg, logger, host, addr, uri, params)
|
||||
if cfg.Settings.LogResponse {
|
||||
logger.Printf("[MSG] %s; %s; Response: %#v\r\n", addr, uri, rst)
|
||||
}
|
||||
|
||||
if rst["RESULT"] != "OK" {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
} else {
|
||||
@ -407,6 +414,9 @@ func handleGetUutInfo(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if cfg.Settings.LogRequest {
|
||||
logger.Printf("[MSG] %s; %s; Request: %#v\r\n", addr, uri, params)
|
||||
}
|
||||
ews := new(ews.EWS)
|
||||
|
||||
switch params["ACTION"] {
|
||||
@ -420,6 +430,10 @@ func handleGetUutInfo(w http.ResponseWriter, r *http.Request) {
|
||||
rst = ews.GetUutInfo(cfg, logger, host, addr, uri, params)
|
||||
}
|
||||
|
||||
if cfg.Settings.LogResponse {
|
||||
logger.Printf("[MSG] %s; %s; Response: Length=%d\r\n", addr, uri, len(rst["ErrMsg"]))
|
||||
}
|
||||
|
||||
if rst["RESULT"] != "OK" {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
} else {
|
||||
|
32
ews/ews.go
32
ews/ews.go
@ -47,9 +47,6 @@ type DefectInfo struct {
|
||||
}
|
||||
|
||||
func (e *EWS) SetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr string, uri string, params map[string]string) map[string]string {
|
||||
if cfg.Settings.LogRequest {
|
||||
logger.Printf("[MSG] %s; %s; Request: %#v\r\n", addr, uri, params)
|
||||
}
|
||||
rst := map[string]string{"RESULT": ""}
|
||||
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s",
|
||||
@ -126,9 +123,6 @@ func (e *EWS) SetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr stri
|
||||
rst["ErrMsg"] = err.Error()
|
||||
return rst
|
||||
}
|
||||
if cfg.Settings.LogResponse {
|
||||
logger.Printf("[MSG] %s; %s; Response: %#v\r\n", addr, uri, rst)
|
||||
}
|
||||
rst["RESULT"] = "OK"
|
||||
rst["ErrMsg"] = "Inserted 1 new record."
|
||||
return rst
|
||||
@ -243,9 +237,6 @@ func (e *EWS) SetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr stri
|
||||
rst["ErrMsg"] = err.Error()
|
||||
return rst
|
||||
}
|
||||
if cfg.Settings.LogResponse {
|
||||
logger.Printf("[MSG] %s; %s; Response: %#v\r\n", addr, uri, rst)
|
||||
}
|
||||
rst["RESULT"] = "OK"
|
||||
rst["ErrMsg"] = "Updated and backed up 1 record."
|
||||
return rst
|
||||
@ -263,17 +254,10 @@ func (e *EWS) SetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr stri
|
||||
}
|
||||
rst["RESULT"] = "OK"
|
||||
rst["ErrMsg"] = "Updated 1 record."
|
||||
if cfg.Settings.LogResponse {
|
||||
logger.Printf("[MSG] %s; %s; Response: %#v\r\n", addr, uri, rst)
|
||||
}
|
||||
return rst
|
||||
}
|
||||
|
||||
func (e *EWS) GetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr string, uri string, params map[string]string) map[string]string {
|
||||
if cfg.Settings.LogRequest {
|
||||
logger.Printf("[MSG] %s; %s; Request: %#v\r\n", addr, uri, params)
|
||||
}
|
||||
|
||||
rst := map[string]string{"RESULT": ""}
|
||||
if params["KEY"] == "" || params["VALUE"] == "" {
|
||||
logger.Printf("[ERR] %s; %s; %#v; %s\r\n", addr, uri, params, "Invalid Parameters !")
|
||||
@ -449,16 +433,11 @@ func (e *EWS) GetUutInfo(cfg cnf.Cfg, logger *log.Logger, host string, addr stri
|
||||
|
||||
rst["RESULT"] = "OK"
|
||||
rst["ErrMsg"] = e.TemplateUutInfo(loc, locTime, misc, last, bkup)
|
||||
if cfg.Settings.LogResponse {
|
||||
logger.Printf("[MSG] %s; %s; Response: Length=%d\r\n", addr, uri, len(rst["ErrMsg"]))
|
||||
}
|
||||
|
||||
return rst
|
||||
}
|
||||
|
||||
func (e *EWS) GetDefectReport(cfg cnf.Cfg, logger *log.Logger, host string, addr string, uri string, params map[string]string) map[string]string {
|
||||
if cfg.Settings.LogRequest {
|
||||
logger.Printf("[MSG] %s; %s; Request: %#v\r\n", addr, uri, params)
|
||||
}
|
||||
rst := map[string]string{"RESULT": ""}
|
||||
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s",
|
||||
@ -526,16 +505,10 @@ func (e *EWS) GetDefectReport(cfg cnf.Cfg, logger *log.Logger, host string, addr
|
||||
|
||||
rst["RESULT"] = "OK"
|
||||
rst["ErrMsg"] = e.TemplateDefectInfo(defect)
|
||||
if cfg.Settings.LogResponse {
|
||||
logger.Printf("[MSG] %s; %s; Response: Length=%d\r\n", addr, uri, len(rst["ErrMsg"]))
|
||||
}
|
||||
return rst
|
||||
}
|
||||
|
||||
func (e *EWS) GetOfflineReport(cfg cnf.Cfg, logger *log.Logger, host string, addr string, uri string, params map[string]string) map[string]string {
|
||||
if cfg.Settings.LogRequest {
|
||||
logger.Printf("[MSG] %s; %s; Request: %#v\r\n", addr, uri, params)
|
||||
}
|
||||
rst := map[string]string{"RESULT": ""}
|
||||
|
||||
dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s",
|
||||
@ -603,9 +576,6 @@ func (e *EWS) GetOfflineReport(cfg cnf.Cfg, logger *log.Logger, host string, add
|
||||
|
||||
rst["RESULT"] = "OK"
|
||||
rst["ErrMsg"] = e.TemplateDefectInfo(offline)
|
||||
if cfg.Settings.LogResponse {
|
||||
logger.Printf("[MSG] %s; %s; Response: Length=%d\r\n", addr, uri, len(rst["ErrMsg"]))
|
||||
}
|
||||
return rst
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user