StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules
(endpoint string, apis []API, modules []string, cors []string, vhosts []string)
| 24 | |
| 25 | // StartHTTPEndpoint starts the HTTP RPC endpoint, configured with cors/vhosts/modules |
| 26 | func StartHTTPEndpoint(endpoint string, apis []API, modules []string, cors []string, vhosts []string) (net.Listener, *Server, error) { |
| 27 | // Generate the whitelist based on the allowed modules |
| 28 | whitelist := make(map[string]bool) |
| 29 | for _, module := range modules { |
| 30 | whitelist[module] = true |
| 31 | } |
| 32 | // Register all the APIs exposed by the services |
| 33 | handler := NewServer() |
| 34 | for _, api := range apis { |
| 35 | if whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) { |
| 36 | if err := handler.RegisterName(api.Namespace, api.Service); err != nil { |
| 37 | return nil, nil, err |
| 38 | } |
| 39 | log.Debug("HTTP registered", "namespace", api.Namespace) |
| 40 | } |
| 41 | } |
| 42 | // All APIs registered, start the HTTP listener |
| 43 | var ( |
| 44 | listener net.Listener |
| 45 | err error |
| 46 | ) |
| 47 | if listener, err = net.Listen("tcp", endpoint); err != nil { |
| 48 | return nil, nil, err |
| 49 | } |
| 50 | go NewHTTPServer(cors, vhosts, handler).Serve(listener) |
| 51 | return listener, handler, err |
| 52 | } |
| 53 | |
| 54 | // StartWSEndpoint starts a websocket endpoint |
| 55 | func StartWSEndpoint(endpoint string, apis []API, modules []string, wsOrigins []string, exposeAll bool) (net.Listener, *Server, error) { |
nothing calls this directly
no test coverage detected