runProxy starts and runs the proxy. l must not be nil. TODO(e.burkov): Move into separate dnssvc package.
(ctx context.Context, l *slog.Logger, conf *configuration)
| 83 | // |
| 84 | // TODO(e.burkov): Move into separate dnssvc package. |
| 85 | func runProxy(ctx context.Context, l *slog.Logger, conf *configuration) (err error) { |
| 86 | var ( |
| 87 | buildVersion = version.Version() |
| 88 | revision = version.Revision() |
| 89 | branch = version.Branch() |
| 90 | commitTime = version.CommitTime() |
| 91 | ) |
| 92 | |
| 93 | l.InfoContext( |
| 94 | ctx, |
| 95 | "dnsproxy starting", |
| 96 | "version", buildVersion, |
| 97 | "revision", revision, |
| 98 | "branch", branch, |
| 99 | "commit_time", commitTime, |
| 100 | ) |
| 101 | |
| 102 | // Prepare the proxy server and its configuration. |
| 103 | proxyConf, err := createProxyConfig(ctx, l, conf) |
| 104 | if err != nil { |
| 105 | return fmt.Errorf("configuring proxy: %w", err) |
| 106 | } |
| 107 | |
| 108 | dnsProxy, err := proxy.New(proxyConf) |
| 109 | if err != nil { |
| 110 | return fmt.Errorf("creating proxy: %w", err) |
| 111 | } |
| 112 | |
| 113 | // Start the proxy server. |
| 114 | err = dnsProxy.Start(ctx) |
| 115 | if err != nil { |
| 116 | return fmt.Errorf("starting dnsproxy: %w", err) |
| 117 | } |
| 118 | |
| 119 | // TODO(e.burkov): Use [service.SignalHandler]. |
| 120 | signalChannel := make(chan os.Signal, 1) |
| 121 | signal.Notify(signalChannel, syscall.SIGINT, syscall.SIGTERM) |
| 122 | <-signalChannel |
| 123 | |
| 124 | // Stopping the proxy. |
| 125 | err = dnsProxy.Shutdown(ctx) |
| 126 | if err != nil { |
| 127 | return fmt.Errorf("stopping dnsproxy: %w", err) |
| 128 | } |
| 129 | |
| 130 | return nil |
| 131 | } |
| 132 | |
| 133 | // runPprof runs pprof server on localhost:6060. |
| 134 | // |
no test coverage detected
searching dependent graphs…