Go 将echo.Context转换为Context.Context

Go 将echo.Context转换为Context.Context,go,graphql,Go,Graphql,我正在编写一个web应用程序,使用Go作为后端。我正在使用这个GraphQL库和EchoWeb框架。问题在于graphql-go库在go中使用context包,而Echo使用自己的自定义上下文,并且取消了对标准context包的支持 我的问题是,在下面的例子中,有没有一种方法可以将context.context用作echo.context api.go func (api *API) Bind(group *echo.Group) { group.Use(middleware.JWTWi

我正在编写一个web应用程序,使用Go作为后端。我正在使用这个GraphQL库和EchoWeb框架。问题在于
graphql-go
库在go中使用
context
包,而
Echo
使用自己的自定义上下文,并且取消了对标准
context
包的支持

我的问题是,在下面的例子中,有没有一种方法可以将context.context用作echo.context

api.go
func (api *API) Bind(group *echo.Group) {
    group.Use(middleware.JWTWithConfig(middleware.JWTConfig{
        SigningKey:  []byte("SOME_REAL_SECRET_KEY"),
        SigningMethod:  "HS256",
    }))
    group.GET("/graphql", api.GraphQLHandler)
    group.POST("/query",  echo.WrapHandler(&relay.Handler{Schema: schema}))
}
graphql.go

func (r *Resolver) Viewer(ctx context.Context, arg *struct{ Token *string }) (*viewerResolver, error) {
    token := ctx.Value("user").(*jwt.Token) // oops on this line, graphql-go uses context.Context, but the echo middleware provides echo.Context
    ...
}
如何使回显上下文可用于我的graphql解析器。非常感谢,非常感谢您的帮助。

回音。上下文不能用作上下文。上下文,但它确实指一个;如果
c
是回送上下文,则
c.Request().context()
是传入请求的
context.context
,例如,如果用户关闭连接,将取消该请求

如果需要,可以使用
Get
方法和
WithValue
方法将其他有用的值从echo上下文复制到stdlib上下文。如果您总是希望复制某些值,那么您可以编写一个helper函数来执行此操作