buildServerData builds the server data for the given server expression.
(svr *expr.ServerExpr, root *expr.RootExpr)
| 182 | |
| 183 | // buildServerData builds the server data for the given server expression. |
| 184 | func buildServerData(svr *expr.ServerExpr, root *expr.RootExpr) *Data { |
| 185 | hosts := make([]*HostData, 0, len(svr.Hosts)) |
| 186 | for _, h := range svr.Hosts { |
| 187 | hosts = append(hosts, buildHostData(h)) |
| 188 | } |
| 189 | |
| 190 | var ( |
| 191 | variables []*VariableData |
| 192 | |
| 193 | foundVars = make(map[string]struct{}) |
| 194 | ) |
| 195 | // collect all the URL variables defined in host expressions |
| 196 | for _, h := range hosts { |
| 197 | for _, v := range h.Variables { |
| 198 | if _, ok := foundVars[v.Name]; ok { |
| 199 | continue |
| 200 | } |
| 201 | variables = append(variables, v) |
| 202 | foundVars[v.Name] = struct{}{} |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | var ( |
| 207 | transports []*TransportData |
| 208 | httpServices []string |
| 209 | grpcServices []string |
| 210 | |
| 211 | foundTrans = make(map[Transport]struct{}) |
| 212 | ) |
| 213 | for _, svc := range svr.Services { |
| 214 | _, seenHTTP := foundTrans[TransportHTTP] |
| 215 | _, seenGRPC := foundTrans[TransportGRPC] |
| 216 | if root.API.HTTP.Service(svc) != nil { |
| 217 | httpServices = append(httpServices, svc) |
| 218 | if !seenHTTP { |
| 219 | transports = append(transports, newHTTPTransport()) |
| 220 | foundTrans[TransportHTTP] = struct{}{} |
| 221 | } |
| 222 | seenHTTP = true |
| 223 | } |
| 224 | if root.API.JSONRPC.Service(svc) != nil { |
| 225 | // JSON-RPC implies HTTP transport; ensure HTTP transport exists |
| 226 | if !seenHTTP { |
| 227 | transports = append(transports, newHTTPTransport()) |
| 228 | foundTrans[TransportHTTP] = struct{}{} |
| 229 | } |
| 230 | } |
| 231 | if root.API.GRPC.Service(svc) != nil { |
| 232 | grpcServices = append(grpcServices, svc) |
| 233 | if !seenGRPC { |
| 234 | transports = append(transports, newGRPCTransport()) |
| 235 | foundTrans[TransportGRPC] = struct{}{} |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | for _, transport := range transports { |
| 240 | switch transport.Type { |
| 241 | case TransportHTTP: |
no test coverage detected