diff --git a/routebuildermdl/responseHanldermdl.go b/routebuildermdl/responseHanldermdl.go index aca37f803784fae4ab27a3863d5ed8aae80f2d88..62dcfd4082d1fb6c414a8b24634377bd815e6da2 100644 --- a/routebuildermdl/responseHanldermdl.go +++ b/routebuildermdl/responseHanldermdl.go @@ -34,7 +34,7 @@ type responseMethod struct { type responseData struct { Result interface{} `json:"result"` Error interface{} `json:"error"` - ResponseHeader interface{} `json:"reponseHeader"` + ResponseHeader interface{} `json:"responseHeader"` ErrorCode int `json:"errorCode"` DebugResponse DebugResponse `json:"debugInfo"` IsCompressed bool `json:"isCompressed"` @@ -96,10 +96,17 @@ func formatResponse(ab *servicebuildermdl.AbstractBusinessLogicHolder, responseD if ab == nil { return responseData } - stackTrace, _ := ab.GetDataResultset("MQLStackTrace") - performanceTrace, _ := ab.GetDataResultset("MQLPerformanceTrace") - responseData.DebugResponse.StackTrace = stackTrace.Value() - responseData.DebugResponse.PerformanceInfo = performanceTrace.Value() + if stackTrace, ok := ab.GetDataResultset("MQLStackTrace"); ok && stackTrace != nil { + responseData.DebugResponse.StackTrace = stackTrace.Value() + } + if performanceTrace, ok := ab.GetDataResultset("MQLPerformanceTrace"); ok && performanceTrace != nil { + responseData.DebugResponse.PerformanceInfo = performanceTrace.Value() + } responseData.ServerTime = time.Now() + if ab.EnableResponseHeaders { + headers := servicebuildermdl.ResponseHeader{} + headers.ServerIP = ab.GetServerIP() + responseData.ResponseHeader = headers + } return responseData } diff --git a/routebuildermdl/routebuilder_fasthttp.go b/routebuildermdl/routebuilder_fasthttp.go index 161d4ea70b8eadbe3043b403880152f73f975c37..20118db2c7490c7a5cf68b224cfd6038a2a51c0b 100644 --- a/routebuildermdl/routebuilder_fasthttp.go +++ b/routebuildermdl/routebuilder_fasthttp.go @@ -202,6 +202,9 @@ func commonHandler(c *routing.Context, isRestricted, isRoleBased, heavyDataActiv if ok { c.Response.Header.Set("Authorization", token) } + if ab.EnableResponseHeaders { + c.Response.Header.Set("serverIP", ab.GetServerIP()) + } } } ba, _ := ffjson.Marshal(responseMap) diff --git a/routebuildermdl/routebuilder_gin.go b/routebuildermdl/routebuilder_gin.go index 8365a57486b4f92abc348c872e317f55f4ce2f66..9316fc6023306fc1dad78150e451c5dcc8ef9087 100644 --- a/routebuildermdl/routebuilder_gin.go +++ b/routebuildermdl/routebuilder_gin.go @@ -1,4 +1,5 @@ -// +build !fasthttp +//go:build !fasthttp +// +build !fasthttp package routebuildermdl @@ -190,6 +191,9 @@ func commonHandler(c *gin.Context, isRestricted, isRoleBased, heavyDataActivity if ab != nil { token, _ := ab.GetDataString("MQLToken") c.Header("Authorization", token) + if ab.EnableResponseHeaders { + c.Header("serverIP", ab.GetServerIP()) + } } } c.JSON(http.StatusOK, responseMap) diff --git a/servicebuildermdl/servicebuildermdl.go b/servicebuildermdl/servicebuildermdl.go index b37ad2111c544f68cd37e2dcd2e4f05d805fc235..e67a4fc3e9874cef49b03e5d510024392db464ad 100644 --- a/servicebuildermdl/servicebuildermdl.go +++ b/servicebuildermdl/servicebuildermdl.go @@ -96,6 +96,10 @@ type DebugInfo struct { PerformanceInfo strings.Builder `json:"performanceInfo"` } +type ResponseHeader struct { + ServerIP string `json:"serverIP"` +} + // LoadData is a method sign for loader methods type LoadData = func(ab *AbstractBusinessLogicHolder) error @@ -104,18 +108,19 @@ type FinalStepProcessOutput = func(ab *AbstractBusinessLogicHolder) (*interface{ // AbstractBusinessLogicHolder use this type to inheritance type AbstractBusinessLogicHolder struct { - localServiceData map[string]interface{} - pricipalObject Principal - globalConfigData map[string]GlobalConfigModel - GlobalErrorCode int - ServiceError interface{} - TransactionEnable bool - DatabaseType string // database type for transaction begin(MYSQL,SQLSERVER etc.) - IgnoreStrictMode bool - Branch string // branch name provided in the header - TXN *sql.Tx // transaction for MySQL - SQLServerTXN *sql.Tx // Transaction for SQLServer - GraphDbTXN *dgo.Txn + localServiceData map[string]interface{} + pricipalObject Principal + globalConfigData map[string]GlobalConfigModel + GlobalErrorCode int + ServiceError interface{} + TransactionEnable bool + DatabaseType string // database type for transaction begin(MYSQL,SQLSERVER etc.) + IgnoreStrictMode bool + Branch string // branch name provided in the header + TXN *sql.Tx // transaction for MySQL + SQLServerTXN *sql.Tx // Transaction for SQLServer + GraphDbTXN *dgo.Txn + EnableResponseHeaders bool } // SetGlobalConfig - SetGlobalConfig @@ -133,6 +138,10 @@ func (ab *AbstractBusinessLogicHolder) SetBranch(branch string) { ab.Branch = branch } +func (ab *AbstractBusinessLogicHolder) SetResponseHeadersFlag(isEnabled bool) { + ab.EnableResponseHeaders = isEnabled +} + // GetDataString will give you string func (ab *AbstractBusinessLogicHolder) GetDataString(key string) (string, bool) { //check in map