1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-03-17 21:07:54 +02:00

fix: if not kratos context then panic will result (#1338)

* fix: if not kratos context panic

当ctx不是kratos的context,则app.Name()会导致panic
This commit is contained in:
Xudong Cai 2021-08-15 17:02:59 +08:00 committed by GitHub
parent 3f68c9a9e0
commit 80378ca10d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,8 +17,10 @@ var _ propagation.TextMapPropagator = Metadata{}
// Inject sets metadata key-values from ctx into the carrier.
func (b Metadata) Inject(ctx context.Context, carrier propagation.TextMapCarrier) {
app, _ := kratos.FromContext(ctx)
carrier.Set(serviceHeader, app.Name())
app, ok := kratos.FromContext(ctx)
if ok {
carrier.Set(serviceHeader, app.Name())
}
}
// Extract returns a copy of parent with the metadata from the carrier added.