...

Source file src/golang.conradwood.net/tests/shared/rpc/contextObject.go

Documentation: golang.conradwood.net/tests/shared/rpc

     1  package rpc
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	apb "golang.conradwood.net/apis/auth"
     7  	"golang.conradwood.net/go-easyops/auth"
     8  	"golang.conradwood.net/go-easyops/tokens"
     9  	"google.golang.org/grpc/metadata"
    10  )
    11  
    12  const (
    13  	current_version = 2
    14  )
    15  
    16  type contextObject struct {
    17  	user    *apb.User
    18  	service *apb.User
    19  }
    20  
    21  func (co *contextObject) NewContext(ctx context.Context) context.Context {
    22  	ctx = context.WithValue(ctx, CTXKEY, co)
    23  	newmd := metadata.Pairs(tokens.METANAME, co.serialize())
    24  	ctx = metadata.NewOutgoingContext(ctx, newmd)
    25  	return ctx
    26  }
    27  
    28  func fromContext(ctx context.Context) *contextObject {
    29  	ifa := (ctx.Value(CTXKEY))
    30  	co := ifa.(*contextObject)
    31  	return co
    32  }
    33  
    34  // multiline description
    35  func (co *contextObject) PrettyString() string {
    36  	ud := ""
    37  	if co.user != nil {
    38  		ud = fmt.Sprintf("[email=%s, id=%s]", co.user.Email, co.user.ID)
    39  	}
    40  	sd := ""
    41  	if co.service != nil {
    42  		sd = fmt.Sprintf("[email=%s, id=%s]", co.service.Email, co.service.ID)
    43  	}
    44  	return fmt.Sprintf("User   : %s %s\nService: %s %s\n",
    45  		auth.Description(co.user), ud,
    46  		auth.Description(co.service), sd,
    47  	)
    48  }
    49  func (co *contextObject) serialize() string {
    50  	panic("THIS USED TO USE THE RPCINTERCEPTOR")
    51  }
    52  

View as plain text