FromMetadata returns The Things Stack metadata from metadata.MD
(md metadata.MD)
| 99 | |
| 100 | // FromMetadata returns The Things Stack metadata from metadata.MD |
| 101 | func FromMetadata(md metadata.MD) MD { |
| 102 | var m MD |
| 103 | if id, ok := md["id"]; ok && len(id) > 0 { |
| 104 | m.ID = id[len(id)-1] |
| 105 | } |
| 106 | if authorization, ok := md["authorization"]; ok && len(authorization) > 0 { |
| 107 | if parts := strings.SplitN(authorization[len(authorization)-1], " ", 2); len(parts) == 2 { |
| 108 | m.AuthType, m.AuthValue = parts[0], parts[1] |
| 109 | } |
| 110 | } |
| 111 | if serviceType, ok := md["service-type"]; ok && len(serviceType) > 0 { |
| 112 | m.ServiceType = serviceType[len(serviceType)-1] |
| 113 | } |
| 114 | if serviceVersion, ok := md["service-version"]; ok && len(serviceVersion) > 0 { |
| 115 | m.ServiceVersion = serviceVersion[len(serviceVersion)-1] |
| 116 | } |
| 117 | if netAddress, ok := md["net-address"]; ok && len(netAddress) > 0 { |
| 118 | m.NetAddress = netAddress[len(netAddress)-1] |
| 119 | } |
| 120 | if host, ok := md["host"]; ok && len(host) > 0 { |
| 121 | m.Host = host[len(host)-1] |
| 122 | } |
| 123 | if uri, ok := md["uri"]; ok && len(uri) > 0 { |
| 124 | m.URI = uri[len(uri)-1] |
| 125 | } |
| 126 | if xForwardedFor, ok := md["x-forwarded-for"]; ok && len(xForwardedFor) > 0 { |
| 127 | m.XForwardedFor = xForwardedFor[len(xForwardedFor)-1] |
| 128 | } |
| 129 | if userAgent, ok := md["grpcgateway-user-agent"]; ok && len(userAgent) > 0 { |
| 130 | m.UserAgent = userAgent[len(userAgent)-1] |
| 131 | } else if userAgent, ok := md["user-agent"]; ok && len(userAgent) > 0 { |
| 132 | m.UserAgent = userAgent[len(userAgent)-1] |
| 133 | } |
| 134 | return m |
| 135 | } |
| 136 | |
| 137 | // FromOutgoingContext returns The Things Stack metadata from the outgoing context ctx. |
| 138 | func FromOutgoingContext(ctx context.Context) (m MD) { |
no outgoing calls
no test coverage detected