StartServiceWithPluginHost builds and runs the proxy service with a shared plugin host.
(cfg *config.Config, configPath string, localPassword string, host *pluginhost.Host)
| 33 | |
| 34 | // StartServiceWithPluginHost builds and runs the proxy service with a shared plugin host. |
| 35 | func StartServiceWithPluginHost(cfg *config.Config, configPath string, localPassword string, host *pluginhost.Host) { |
| 36 | builder := cliproxy.NewBuilder(). |
| 37 | WithConfig(cfg). |
| 38 | WithConfigPath(configPath). |
| 39 | WithLocalManagementPassword(localPassword). |
| 40 | WithHooks(cliproxy.Hooks{ |
| 41 | OnAfterStart: func(_ *cliproxy.Service) { |
| 42 | startBridge(cfg) |
| 43 | }, |
| 44 | }) |
| 45 | if host != nil { |
| 46 | builder = builder.WithPluginHost(host) |
| 47 | } |
| 48 | |
| 49 | ctxSignal, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) |
| 50 | defer cancel() |
| 51 | |
| 52 | runCtx := ctxSignal |
| 53 | if localPassword != "" { |
| 54 | var keepAliveCancel context.CancelFunc |
| 55 | runCtx, keepAliveCancel = context.WithCancel(ctxSignal) |
| 56 | builder = builder.WithServerOptions(api.WithKeepAliveEndpoint(10*time.Second, func() { |
| 57 | log.Warn("keep-alive endpoint idle for 10s, shutting down") |
| 58 | keepAliveCancel() |
| 59 | })) |
| 60 | } |
| 61 | |
| 62 | service, err := builder.Build() |
| 63 | if err != nil { |
| 64 | log.Errorf("failed to build proxy service: %v", err) |
| 65 | return |
| 66 | } |
| 67 | |
| 68 | err = service.Run(runCtx) |
| 69 | if err != nil && !errors.Is(err, context.Canceled) { |
| 70 | log.Errorf("proxy service exited with error: %v", err) |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // StartExampleAPIKeyWarningServer starts a warning-only server for unsafe template API keys. |
| 75 | func StartExampleAPIKeyWarningServer(cfg *config.Config, configPath string, keys []string) { |
no test coverage detected