add http transport (#1060)

* add http transport

* delete method and path
pull/1064/head
longxboy 4 years ago committed by GitHub
parent 7f72b72ddb
commit 60b1e593f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      transport/http/client.go
  2. 3
      transport/http/server.go
  3. 24
      transport/http/transport.go

@ -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…
Cancel
Save