tags/

directory
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 6, 2021 License: MIT

README

Tags

A set of interceptors for Client and Server for appending or forwarding selective metadata tags in the context.

  1. append (client/server) --> append tags e.g., "mkit-from-service" to outgoing
  2. forward (server) --> copy tags e.g., "mkit-trace-id" from incoming to outgoing

Usage

    // Server
	grpcServer := grpc.NewServer(
		grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(
			append.UnaryServerInterceptor(append.WithPairs(constants.FromServiceKey, "account-service")),
            forward.UnaryServerInterceptor(forward.WithForwardTags(constants.TraceIDKey)),
		)),
	)
    // Client 
    var ucInterceptors = []grpc.UnaryClientInterceptor{
        appendTags.UnaryClientInterceptor(appendTags.WithTraceID(), appendTags.WithPairs(constants.FromServiceKey, constants.ACCOUNT_CLIENT)),
    }
    dialOptions = append(dialOptions, grpc.WithUnaryInterceptor(grpc_middleware.ChainUnaryClient(ucInterceptors...)))
    clientConn, err = grpc.Dial(service.Endpoint, dialOptions...)

Access Tags in your handler

outgoingMd := metautils.ExtractIncoming(ctx)
println( outgoingMd.Get(constants.TraceIDKey)))
println( outgoingMd.Get(constants.TenantIdKey)))
println( outgoingMd.Get(constants.FromServiceKey)))

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL