mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-10 00:29:01 +02:00
149fc0195e
* add application info * add base context * add client target
24 lines
515 B
Go
24 lines
515 B
Go
package kratos
|
|
|
|
import "context"
|
|
|
|
// AppInfo is application context value.
|
|
type AppInfo struct {
|
|
ID string
|
|
Name string
|
|
Version 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
|
|
}
|