go-micro.dev/v5@v5.12.0/server/context.go (about)

     1  package server
     2  
     3  import (
     4  	"context"
     5  	"sync"
     6  )
     7  
     8  type serverKey struct{}
     9  type wgKey struct{}
    10  
    11  func wait(ctx context.Context) *sync.WaitGroup {
    12  	if ctx == nil {
    13  		return nil
    14  	}
    15  	wg, ok := ctx.Value(wgKey{}).(*sync.WaitGroup)
    16  	if !ok {
    17  		return nil
    18  	}
    19  	return wg
    20  }
    21  
    22  func FromContext(ctx context.Context) (Server, bool) {
    23  	c, ok := ctx.Value(serverKey{}).(Server)
    24  	return c, ok
    25  }
    26  
    27  func NewContext(ctx context.Context, s Server) context.Context {
    28  	return context.WithValue(ctx, serverKey{}, s)
    29  }