Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GrpcLogger ¶
func GrpcLogger( ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler, ) (resp interface{}, err error)
** GRPC INTERCEPTOR ** GRPC interceptor to log requests in the terminal UnaryServerInterceptor: func(ctx context.Context, req any, info *UnaryServerInfo, handler UnaryHandler) (resp any, err error)
func HttpLogger ¶
* HTTP MIDDLEWARE The above GrpcLogger middleware will work only for gRPC requests. If we try to send an HTTP request to the gateway server, we won't see any logs written. That's because we're using in-process translation on our gateway server . So the gateway will call the RPC handler function directly without going through any interceptors. If we run the gateway as a separate server, And use cross-process translation to call the gRPC server via a network call, Then the logs will show up in the gRPC server as normal. But that's another network hop that can increase the duration of the request. So, if we still want to keep using in-process translation, we will have to write a separate HTTP middleware to log the HTTP requests.
Types ¶
type ResponseRecorder ¶
type ResponseRecorder struct { http.ResponseWriter // embed the oroginal http.ResponseWriter // this StatusCode field will be updated to the correct value when the // WriteHeader method is called by the handler function. StatusCode int // In case of the error, it will be written to the response body // so we need to track the response body as well. Body []byte }
ResponseRecorder struct that implements the http.ResponseWriter interface to track the status code and response body of the HTTP response from the handler.
func (*ResponseRecorder) WriteHeader ¶
func (rec *ResponseRecorder) WriteHeader(statusCode int)