我正在尝试设置 buffalo 将数据发送到 AWS X-Ray。我是 buffalo/go 的新手,我完全迷失在文档中......
我的行动.go
package actions
import (
"fmt"
"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/envy"
"github.com/aws/aws-xray-sdk-go/xray"
contenttype "github.com/gobuffalo/mw-contenttype"
"github.com/gobuffalo/x/sessions"
"github.com/rs/cors"
)
var ENV = envy.Get("GO_ENV", "development")
var app *buffalo.App
func App() *buffalo.App {
if app == nil {
app = buffalo.New(buffalo.Options{
Env: ENV,
SessionStore: sessions.Null{},
PreWares: []buffalo.PreWare{
cors.Default().Handler,
},
SessionName: "__session",
})
app.Use(contenttype.Set("application/json"))
app.Use(XRayStart)
app.GET("/", HomeHandler)
}
return app
}
// XRayStart starts xray
func XRayStart(next buffalo.Handler) buffalo.Handler {
return func(c buffalo.Context) error {
fmt.Println("1")
h := xray.Handler(xray.NewFixedSegmentNamer("WordAPI"), buffalo.WrapBuffaloHandler(next))
fmt.Println(h)
err := next(c)
return err
}
}
func init() {
fmt.Println("init")
xray.Configure(xray.Config{
DaemonAddr: "127.0.0.1:2000", // default
ServiceVersion: "1.2.3",
})
}
当我卷曲时,我从 HomeHandler 得到正确的响应,并且中间件内的日志打印出来(h 不为空)。init 也被正确调用。在恶魔方面,我什么也看不到:(
官方文档有这个示例代码
func main() {
http.Handle("/", xray.Handler(xray.NewFixedSegmentNamer("myApp"), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello!"))
})))
http.ListenAndServe(":8000", nil)
}
我想我的端口不正确..
关于如何进行的任何建议?
谢谢