-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
44 lines (36 loc) · 1011 Bytes
/
metadata.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
44
package xshare
import (
"github.com/hwcer/cosgo/binder"
"strconv"
)
const (
//ServicesMetadataVersion = "ver"
ServicesMetadataAverage = "Average"
//ServicesMetadataServerId = "sid"
ServicesMetadataRpcServerId = "_rpc_srv_id" //服务器编号
ServicesMetadataRpcServerAddress = "_rpc_srv_addr" //rpc服务器ID,selector 中固定转发地址
//ServicesMetadataNetRequestId = "_net_req_id"
)
// NewMetadata 创建新Metadata,参数k1,v1,k2,v2...
func NewMetadata(args ...string) Metadata {
r := Metadata{}
var i, j int
for i = 0; i < len(args)-1; i += 2 {
j = i + 1
r[args[i]] = args[j]
}
return r
}
type Metadata map[string]string
func (this Metadata) SetAddress(v string) {
this[ServicesMetadataRpcServerAddress] = v
}
func (this Metadata) SetServerId(v int32) {
this[ServicesMetadataRpcServerId] = strconv.Itoa(int(v))
}
func (this Metadata) SetContentType(v string) {
this[binder.ContentType] = v
}
func (this Metadata) Json() map[string]string {
return this
}