1
0
mirror of https://github.com/go-kratos/kratos.git synced 2025-01-07 23:02:12 +02:00
kratos/context.go
Tony Chen 99719dd667
cmd: update cmd version (#1040)
* update cmd version

* update app info
2021-06-13 01:07:43 +08:00

28 lines
575 B
Go

package kratos
import (
"context"
)
// AppInfo is application context value.
type AppInfo struct {
ID string
Name string
Version string
Metadata map[string]string
Endpoints []string
}
type appKey struct{}
// NewContext returns a new Context that carries value.
func NewContext(ctx context.Context, s AppInfo) context.Context {
return context.WithValue(ctx, appKey{}, s)
}
// FromContext returns the Transport value stored in ctx, if any.
func FromContext(ctx context.Context) (s AppInfo, ok bool) {
s, ok = ctx.Value(appKey{}).(AppInfo)
return
}