cp

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: Apache-2.0 Imports: 2 Imported by: 3

README

Build Status Go Report Card

Context Propagation Go

This middleware is used for support propagate context between micro services.

For this version, we propagate context by opentracing baggage protocol.

Supported framework for auto inject and extract:

How to use

Operate data from context

Before get or set data from context, you should enable auto inject and extract.

go get -u github.com/AminoApps/context-propagation-go
package main

import "github.com/AminoApps/context-propagation-go"


ctx = cp.SetValueToContext(ctx, "my-key", "my-value")

valye := cp.GetValueFromContext(context.Background(), "my-key")
Auto inject and extract
Gin
go get -u github.com/AminoApps/context-propagation-go/module/context-propagation-gin
package main 

import "github.com/AminoApps/context-propagation-go/module/context-propagation-gin"

e := gin.New()
e.Use(cpgin.Middleware())
Http Client/Server
go get -u github.com/AminoApps/context-propagation-go/module/context-propagation-http
package main

import "github.com/AminoApps/context-propagation-go/module/context-propagation-http"

http.ListenAndServe(":8080", cphttp.Wrap(myHandler))

client := cphttp.WrapClient(&http.Client{})

// Please use the ctxhttp to wrap the request.
resp, err := ctxhttp.Get(ctx, client, "http://127.0.0.1:8080/test")
Grpc Client/Server
go get -u github.com/AminoApps/context-propagation-go/module/context-propagation-grpc
package main

import "github.com/AminoApps/context-propagation-go/module/context-propagation-grpc"

server := grpc.NewServer(grpc.UnaryInterceptor(cpgrpc.NewUnaryServerInterceptor()))

client := grpc.Dial(address, grpc.WithUnaryInterceptor(cpgrpc.NewUnaryClientInterceptor()))

Documentation

Index

Constants

View Source
const (
	BaggagePrefix = "baggage-"
)

Variables

This section is empty.

Functions

func Extract

func Extract(carrier map[string]string) map[string]string

func GetValueFromContext

func GetValueFromContext(c context.Context, key string) string

func Inject

func Inject(carrier interface{}) map[string]string

func SetValueToContext

func SetValueToContext(c context.Context, key string, val string) context.Context

Types

type InternalContextKey

type InternalContextKey struct{}

Directories

Path Synopsis
module

Jump to

Keyboard shortcuts

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