MCPcopy Create free account
hub / github.com/goadesign/goa / buildHostData

Function buildHostData

codegen/example/server_data.go:267–340  ·  view source on GitHub ↗

buildHostData builds the host data for the given host expression.

(host *expr.HostExpr)

Source from the content-addressed store, hash-verified

265
266// buildHostData builds the host data for the given host expression.
267func buildHostData(host *expr.HostExpr) *HostData {
268 uris := make([]*URIData, len(host.URIs))
269 for i, uv := range host.URIs {
270 var (
271 t *TransportData
272 scheme string
273 port string
274
275 ustr = string(uv)
276 )
277 // Did not use url package to find scheme because the url may
278 // contain params (i.e. http://{version}.example.com) which needs
279 // substition for url.Parse to succeed. Also URIs in host must have
280 // a scheme otherwise validations would have failed.
281 switch {
282 case strings.HasPrefix(ustr, "https"):
283 scheme = "https"
284 port = "443"
285 t = newHTTPTransport()
286 case strings.HasPrefix(ustr, "http"):
287 scheme = "http"
288 port = "80"
289 t = newHTTPTransport()
290 case strings.HasPrefix(ustr, "grpcs"):
291 scheme = "grpcs"
292 port = "8443"
293 t = newGRPCTransport()
294 case strings.HasPrefix(ustr, "grpc"):
295 scheme = "grpc"
296 port = "8080"
297 t = newGRPCTransport()
298
299 // No need for default case here because we only support the above
300 // possibilites for the scheme. Invalid scheme would have failed
301 // validations in the first place.
302 }
303 uris[i] = &URIData{
304 Scheme: scheme,
305 URL: ustr,
306 Port: port,
307 Transport: t,
308 }
309 }
310
311 vars := expr.AsObject(host.Variables.Type)
312 var variables []*VariableData
313 if len(*vars) > 0 {
314 variables = make([]*VariableData, len(*vars))
315 for i, v := range *vars {
316 def := v.Attribute.DefaultValue
317 var values []string
318 if def == nil {
319 def = v.Attribute.Validation.Values[0]
320 // DSL ensures v.Attribute has either a
321 // default value or an enum validation
322 values = convertToString(v.Attribute.Validation.Values...)
323 }
324 variables[i] = &VariableData{

Callers 1

buildServerDataFunction · 0.85

Calls 6

AsObjectFunction · 0.92
GoifyFunction · 0.92
newHTTPTransportFunction · 0.85
newGRPCTransportFunction · 0.85
convertToStringFunction · 0.85
SchemesMethod · 0.45

Tested by

no test coverage detected