1 Star 0 Fork 0

menuiis / gkit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
transport_http.go 1.71 KB
一键复制 编辑 原始数据 按行查看 历史
SongZhibin97 提交于 2021-12-07 10:50 . style: format code
package trace
import (
"context"
"net/http"
)
// Transport is an HTTP transport.
type Transport struct {
endpoint string
operation string
reqHeader headerCarrier
replyHeader headerCarrier
request *http.Request
pathTemplate string
}
// Kind returns the transport kind.
func (tr *Transport) Kind() Kind {
return KindHTTP
}
// Endpoint returns the transport endpoint.
func (tr *Transport) Endpoint() string {
return tr.endpoint
}
// Operation returns the transport operation.
func (tr *Transport) Operation() string {
return tr.operation
}
// Request returns the HTTP request.
func (tr *Transport) Request() *http.Request {
return tr.request
}
// RequestHeader returns the request header.
func (tr *Transport) RequestHeader() Header {
return tr.reqHeader
}
// ResponseHeader returns the reply header.
func (tr *Transport) ResponseHeader() Header {
return tr.replyHeader
}
// PathTemplate returns the http path template.
func (tr *Transport) PathTemplate() string {
return tr.pathTemplate
}
// SetOperation sets the transport operation.
func SetOperation(ctx context.Context, op string) {
if tr, ok := FromServerTransportContext(ctx); ok {
if tr, ok := tr.(*Transport); ok {
tr.operation = op
}
}
}
type headerCarrier http.Header
// Get returns the value associated with the passed key.
func (hc headerCarrier) Get(key string) string {
return http.Header(hc).Get(key)
}
// Set stores the key-value pair.
func (hc headerCarrier) Set(key string, value string) {
http.Header(hc).Set(key, value)
}
// Keys lists the keys stored in this carrier.
func (hc headerCarrier) Keys() []string {
keys := make([]string, 0, len(hc))
for k := range http.Header(hc) {
keys = append(keys, k)
}
return keys
}
Go
1
https://gitee.com/menciis/gkit.git
git@gitee.com:menciis/gkit.git
menciis
gkit
gkit
4f74120a101e

搜索帮助