The current repo belongs to Paused status, and some functions are restricted. For details, please refer to the description of repo status
2 Star 0 Fork 1

JUMEI_ARCH/go-plugins
Paused

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
awsxray.go 1.56 KB
Copy Edit Raw Blame History
Asim Aslam authored 2018-04-10 15:36 . move awsxray
// Package awsxray is a micro plugin for whitelisting service requests
package awsxray
import (
"net/http"
"github.com/asim/go-awsxray"
"github.com/micro/cli"
"github.com/micro/go-micro/client"
xray "github.com/micro/go-plugins/wrapper/trace/awsxray"
"github.com/micro/micro/plugin"
)
type awsXRay struct {
opts Options
x *awsxray.AWSXRay
}
func (x *awsXRay) Flags() []cli.Flag {
return nil
}
func (x *awsXRay) Commands() []cli.Command {
return nil
}
func (x *awsXRay) Handler() plugin.Handler {
return func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
s := newSegment(x.opts.Name, r)
// use our own writer
xw := &writer{w, 200}
// serve request
h.ServeHTTP(xw, r)
// set status
complete(s, xw.status)
// send segment asynchronously
go x.x.Record(s)
})
}
}
func (x *awsXRay) Init(ctx *cli.Context) error {
opts := []xray.Option{
xray.WithName(x.opts.Name),
xray.WithClient(x.opts.Client),
xray.WithDaemon(x.opts.Daemon),
}
// setup client
c := client.DefaultClient
c = xray.NewClientWrapper(opts...)(c)
c.Init(client.WrapCall(xray.NewCallWrapper(opts...)))
client.DefaultClient = c
return nil
}
func (x *awsXRay) String() string {
return "awsxray"
}
func NewXRayPlugin(opts ...Option) plugin.Plugin {
options := Options{
Name: "go.micro.http",
Daemon: "localhost:2000",
}
for _, o := range opts {
o(&options)
}
return &awsXRay{
opts: options,
x: awsxray.New(
awsxray.WithDaemon(options.Daemon),
awsxray.WithClient(options.Client),
),
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/JMArch/go-plugins.git
git@gitee.com:JMArch/go-plugins.git
JMArch
go-plugins
go-plugins
v0.9.3

Search

0d507c66 1850385 C8b1a773 1850385