From 4d861f037e076a157394b8f387c9174a62f90c04 Mon Sep 17 00:00:00 2001 From: "sati.ac" Date: Thu, 13 Jul 2023 23:19:43 +0300 Subject: [PATCH] feat(AntiGateV2): more verbose debug logging --- api/AntiGateV2.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/api/AntiGateV2.go b/api/AntiGateV2.go index 95fc526..4b6c013 100644 --- a/api/AntiGateV2.go +++ b/api/AntiGateV2.go @@ -209,7 +209,7 @@ func (a *antigateV2Api) getBalance(struct{}) any { }{0, 0, balance.InexactFloat64()} } -func jsonHandler[T any](handler func(data T) any) func(http.ResponseWriter, *http.Request) { +func jsonHandler[T any](api *antigateV2Api, handler func(data T) any) func(http.ResponseWriter, *http.Request) { emptyRequest := reflect.Zero(reflect.TypeOf(handler).In(0)).Interface().(T) return func(w http.ResponseWriter, r *http.Request) { @@ -223,7 +223,9 @@ func jsonHandler[T any](handler func(data T) any) func(http.ResponseWriter, *htt return } + api.ctx.Logger.WithFields(logrus.Fields{"handler": api.Name(), "request": request}).Debug("request") response := handler(request) + api.ctx.Logger.WithFields(logrus.Fields{"handler": api.Name(), "response": response}).Debug("response") marshaled, _ := json.Marshal(response) w.Write(marshaled) @@ -233,9 +235,9 @@ func jsonHandler[T any](handler func(data T) any) func(http.ResponseWriter, *htt func newAntigateV2Api(ctx *ApiContext) ApiHandler { api := &antigateV2Api{ctx, http.NewServeMux()} - api.mux.HandleFunc("/createTask", jsonHandler(api.createTask)) - api.mux.HandleFunc("/getTaskResult", jsonHandler(api.getTaskResult)) - api.mux.HandleFunc("/getBalance", jsonHandler(api.getBalance)) + api.mux.HandleFunc("/createTask", jsonHandler(api, api.createTask)) + api.mux.HandleFunc("/getTaskResult", jsonHandler(api, api.getTaskResult)) + api.mux.HandleFunc("/getBalance", jsonHandler(api, api.getBalance)) return api }