1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00
go-micro/server/context.go
David Brouwer a3980c2308
feat: add test framework & refactor RPC server (#2579)
Co-authored-by: Rene Jochum <rene@jochum.dev>
2022-10-20 13:00:50 +02:00

30 lines
490 B
Go

package server
import (
"context"
"sync"
)
type serverKey struct{}
type wgKey struct{}
func wait(ctx context.Context) *sync.WaitGroup {
if ctx == nil {
return nil
}
wg, ok := ctx.Value(wgKey{}).(*sync.WaitGroup)
if !ok {
return nil
}
return wg
}
func FromContext(ctx context.Context) (Server, bool) {
c, ok := ctx.Value(serverKey{}).(Server)
return c, ok
}
func NewContext(ctx context.Context, s Server) context.Context {
return context.WithValue(ctx, serverKey{}, s)
}