Finalize initializes the server services and/or host with default values if not set explicitly in the design.
()
| 75 | // Finalize initializes the server services and/or host with default values if |
| 76 | // not set explicitly in the design. |
| 77 | func (s *ServerExpr) Finalize() { |
| 78 | if len(s.Services) == 0 { |
| 79 | s.Services = make([]string, len(Root.Services)) |
| 80 | for i, svc := range Root.Services { |
| 81 | s.Services[i] = svc.Name |
| 82 | } |
| 83 | } |
| 84 | if len(s.Hosts) == 0 { |
| 85 | s.Hosts = []*HostExpr{{ |
| 86 | Name: "svc", |
| 87 | Description: "Service host", |
| 88 | URIs: []URIExpr{"http://localhost:80", "grpc://localhost:8080"}, |
| 89 | }} |
| 90 | } |
| 91 | for _, svc := range s.Services { |
| 92 | hasHTTP := Root.API.HTTP.Service(svc) != nil || Root.API.JSONRPC.Service(svc) != nil |
| 93 | hasGRPC := Root.API.GRPC.Service(svc) != nil |
| 94 | for _, h := range s.Hosts { |
| 95 | if hasHTTP && !h.HasHTTPScheme() { |
| 96 | // if a service defines HTTP transport make sure the host defines a |
| 97 | // default HTTP server if not already defined. |
| 98 | h.URIs = append(h.URIs, URIExpr("http://localhost:80")) |
| 99 | } |
| 100 | if hasGRPC && !h.HasGRPCScheme() { |
| 101 | // if a service defines gRPC transport make sure the host defines a |
| 102 | // default gRPC server if not already defined. |
| 103 | h.URIs = append(h.URIs, URIExpr("grpc://localhost:8080")) |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | for _, h := range s.Hosts { |
| 108 | h.Finalize() |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // Schemes returns the list of transport schemes used by all the server |
| 113 | // endpoints. The possible values for the elements of the returned slice are |
nothing calls this directly
no test coverage detected