micro/util/ctx/ctx.go

19 lines
316 B
Go
Raw Normal View History

2019-05-30 23:52:10 +01:00
package ctx
import (
"context"
"net/http"
"strings"
"github.com/micro/go-micro/v2/metadata"
2019-05-30 23:52:10 +01:00
)
func FromRequest(r *http.Request) context.Context {
ctx := context.Background()
md := make(metadata.Metadata)
for k, v := range r.Header {
md[k] = strings.Join(v, ",")
}
return metadata.NewContext(ctx, md)
}