-
Notifications
You must be signed in to change notification settings - Fork 0
/
codec.go
43 lines (36 loc) · 1.03 KB
/
codec.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package micro
import (
"strings"
)
var (
DefaultCodecs = map[string]string{
"text/html": "application/grpc+bytes",
"text/plain": "application/grpc+bytes",
"application/grpc+json": "application/grpc+json",
"application/grpc+proto": "application/grpc+proto",
"application/grpc+bytes": "application/grpc+bytes",
"application/json": "application/grpc+json",
"application/grpc": "application/grpc+proto",
"application/protobuf": "application/grpc+proto",
"application/octet-stream": "application/grpc+bytes",
}
)
const (
HeaderNode = "X-Node-Id" // 限定 node
TokenHeader = "X-Auth-Token" // 认证头
ContentType = "Content-Type"
Accept = "Accept"
)
func MatchCodec(protocol, codec string) bool {
s := strings.Split(protocol, "+")
if len(s) < 2 {
return protocol == codec
}
return s[1] == codec
}
type Protocols struct {
ContentType string // 原始 ContentType
Accept string // 原始 Accept
Reqeust string // 请求
Response string // 返回
}