CloudyGo
212 subscribers
8 photos
1 video
1 file
41 links
Software Engineering & Development Best Practices, Especially in Golang!


https://cloudygo.ir

@rezakhademix
Download Telegram
نوشتن middleware برای اجرا مجموعه‌ای پروسه‌ها قبل از رسیدن درخواست به هندلر برای gRPC سرور کار دشواری نیست.

اما خب اگر تمایل دارین پکیجی استفاده کنین که خودش خودکار لاگ بزنه و ردیابی رو‌ با استانداردهای Otel در اختیارتون قرار بده و‌ مواردی
مثل:
Auth,
Metrics (Prometheus),
Logging,
Selector,
Validator,
Ratelimit

و غیره رو خیلی راحت‌تر داشته باشین، یه نگاهی به پکیج زیر بندازین.

نمونه کد:

 grpcSrv := grpc.NewServer(
grpc.StatsHandler(otelgrpc.NewServerHandler()),
grpc.ChainUnaryInterceptor(
srvMetrics.UnaryServerInterceptor(grpcprom.WithExemplarFromContext(exemplarFromContext)),
logging.UnaryServerInterceptor(interceptorLogger(rpcLogger), logging.WithFieldsFromContext(logTraceID)),
selector.UnaryServerInterceptor(auth.UnaryServerInterceptor(authFn), selector.MatchFunc(allButHealthZ)),
recovery.UnaryServerInterceptor(recovery.WithRecoveryHandler(grpcPanicRecoveryHandler)),
),
)

https://github.com/grpc-ecosystem/go-grpc-middleware



#package
#golang
👍3🙏1