当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
2 Star 0 Fork 1

JUMEI_ARCH/go-plugins
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
awsxray.go 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
Asim Aslam 提交于 2016-12-08 20:19 . name option not needed
// Package awsxray is a micro plugin for whitelisting service requests
package awsxray
import (
"net/http"
"github.com/micro/cli"
"github.com/micro/go-awsxray"
"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),
),
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/JMArch/go-plugins.git
git@gitee.com:JMArch/go-plugins.git
JMArch
go-plugins
go-plugins
v0.5.0

搜索帮助