feat(AntiGateV2): more verbose debug logging
This commit is contained in:
		@ -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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user