mirror of
https://github.com/go-kratos/kratos.git
synced 2025-01-07 23:02:12 +02:00
add http transport (#1060)
* add http transport * delete method and path
This commit is contained in:
parent
7f72b72ddb
commit
60b1e593f1
@ -199,9 +199,8 @@ func (client *Client) Invoke(ctx context.Context, method, path string, args inte
|
||||
ctx = transport.NewClientContext(ctx, &Transport{
|
||||
endpoint: client.opts.endpoint,
|
||||
header: headerCarrier(req.Header),
|
||||
path: path,
|
||||
method: method,
|
||||
operation: c.operation,
|
||||
request: req,
|
||||
})
|
||||
return client.invoke(ctx, req, args, reply, c)
|
||||
}
|
||||
|
@ -164,10 +164,9 @@ func (s *Server) filter() mux.MiddlewareFunc {
|
||||
}
|
||||
tr := &Transport{
|
||||
endpoint: s.endpoint.String(),
|
||||
path: req.RequestURI,
|
||||
method: req.Method,
|
||||
operation: req.RequestURI,
|
||||
header: headerCarrier(req.Header),
|
||||
request: req,
|
||||
}
|
||||
if r := mux.CurrentRoute(req); r != nil {
|
||||
if path, err := r.GetPathTemplate(); err == nil {
|
||||
|
@ -14,10 +14,9 @@ var (
|
||||
// Transport is an HTTP transport.
|
||||
type Transport struct {
|
||||
endpoint string
|
||||
path string
|
||||
method string
|
||||
operation string
|
||||
header headerCarrier
|
||||
request *http.Request
|
||||
}
|
||||
|
||||
// Kind returns the transport kind.
|
||||
@ -40,24 +39,9 @@ func (tr *Transport) Header() transport.Header {
|
||||
return tr.header
|
||||
}
|
||||
|
||||
// Path returns the Transport path from server context.
|
||||
func Path(ctx context.Context) string {
|
||||
if tr, ok := transport.FromServerContext(ctx); ok {
|
||||
if tr, ok := tr.(*Transport); ok {
|
||||
return tr.path
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// Method returns the Transport method from server context.
|
||||
func Method(ctx context.Context) string {
|
||||
if tr, ok := transport.FromServerContext(ctx); ok {
|
||||
if tr, ok := tr.(*Transport); ok {
|
||||
return tr.method
|
||||
}
|
||||
}
|
||||
return ""
|
||||
// Request returns the transport request.
|
||||
func (tr *Transport) Request() *http.Request {
|
||||
return tr.request
|
||||
}
|
||||
|
||||
// SetOperation sets the transport operation.
|
||||
|
Loading…
Reference in New Issue
Block a user