// Capture (for lack of a better name) captures context values of interest
// from the incoming request. Unlike Welcome, values captured here are
// intended to be used only throughout the gokit server flow: (request decoding, business logic, response encoding)
Capture (for lack of a better name) captures context values of interest
from the incoming request. Unlike Welcome, values captured here are
intended to be used only throughout the gokit server flow: (request decoding, business logic, response encoding)
// Capture ( for lack of a better name ) captures context values of interest // from the incoming request . Unlike Welcome values captured here are // intended to be used only throughout the gokit server flow : ( request decoding business logic response encoding )
func Capture(logger kitlog.Logger) kithttp.RequestFunc {
	var transactionInfoLogger = logging.Info(logger)
	return func(ctx context.Context, r *http.Request) (nctx context.Context) {
		var tid string
		if tid = r.Header.Get(HeaderWPATID); tid == "" {
			tid = GenTID()
		}
		nctx = context.WithValue(ctx, ContextKeyRequestTID, tid)
		var satClientID = "N/A"
		if auth, ok := bascule.FromContext(r.Context()); ok {
			satClientID = auth.Token.Principal()
		}
		var source string
		host, _, err := net.SplitHostPort(r.RemoteAddr)
		if err != nil {
			source = r.RemoteAddr
		} else {
			source = host
		}
		logKVs := []interface{}{logging.MessageKey(), "record",
			"request", Request{
				Address: source,
				Path:    r.URL.Path,
				Query:   r.URL.RawQuery,
				Method:  r.Method,
			},
			"tid", tid,
			"satClientID", satClientID,
		}
		logKVs, _ = candlelight.AppendTraceInfo(ctx, logKVs)
		transactionInfoLogger := kitlog.WithPrefix(transactionInfoLogger, logKVs...)
		return context.WithValue(nctx, ContextKeyTransactionInfoLogger, transactionInfoLogger)
	}
}
func Capture ( logger kitlog . Logger ) kithttp . RequestFunc { var transactionInfoLogger = logging . Info ( logger ) return func ( ctx context . Context , r * http . Request ) ( nctx context . Context ) { var tid string if tid = r . Header . Get ( HeaderWPATID ) ; tid == " " { tid = GenTID ( ) } nctx = context . WithValue ( ctx , ContextKeyRequestTID , tid ) var satClientID = " " if auth , ok := bascule . FromContext ( r . Context ( ) ) ; ok { satClientID = auth . Token . Principal ( ) } var source string host , _ , err := net . SplitHostPort ( r . RemoteAddr ) if err != nil { source = r . RemoteAddr } else { source = host } logKVs := [ ] interface { } { logging . MessageKey ( ) , " " , " " , Request { Address : source , Path : r . URL . Path , Query : r . URL . RawQuery , Method : r . Method , } , " " , tid , " " , satClientID , } logKVs , _ = candlelight . AppendTraceInfo ( ctx , logKVs ) transactionInfoLogger := kitlog . WithPrefix ( transactionInfoLogger , logKVs ... ) return context . WithValue ( nctx , ContextKeyTransactionInfoLogger , transactionInfoLogger ) } }
Capture (for lack of a better name) captures context values of interest
from the incoming request.
Capture ( for lack of a better name ) captures context values of interest from the incoming request .
// retrieve satClientID from request context