MCPcopy Index your code
hub / github.com/PasarGuard/node / main

Function main

cmd/node/main.go:19–62  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

17)
18
19func main() {
20 cfg, err := config.Load()
21 if err != nil {
22 log.Fatal(err)
23 }
24
25 addr := fmt.Sprintf("%s:%d", cfg.NodeHost, cfg.ServicePort)
26
27 tlsConfig, err := tlsutil.LoadTLSCredentials(cfg.SslCertFile, cfg.SslKeyFile)
28 if err != nil {
29 log.Fatal(err)
30 }
31
32 log.Printf("Starting Node: v%s", controller.NodeVersion)
33
34 var shutdownFunc func(ctx context.Context) error
35 var service controller.Service
36
37 if cfg.ServiceProtocol == "rest" {
38 shutdownFunc, service, err = rest.StartHttpListener(tlsConfig, addr, cfg)
39 } else {
40 shutdownFunc, service, err = rpc.StartGRPCListener(tlsConfig, addr, cfg)
41 }
42 if err != nil {
43 log.Fatal(err)
44 }
45
46 defer service.Disconnect()
47
48 stopChan := make(chan os.Signal, 1)
49 signal.Notify(stopChan, os.Interrupt, syscall.SIGTERM)
50
51 <-stopChan
52 log.Println("Shutting down server...")
53
54 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
55 defer cancel()
56
57 if err = shutdownFunc(ctx); err != nil {
58 log.Printf("Server shutdown error: %v", err)
59 }
60
61 log.Println("Server gracefully stopped")
62}

Callers

nothing calls this directly

Calls 5

DisconnectMethod · 0.95
LoadFunction · 0.92
LoadTLSCredentialsFunction · 0.92
StartHttpListenerFunction · 0.92
StartGRPCListenerFunction · 0.92

Tested by

no test coverage detected