MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / StartServiceWithPluginHost

Function StartServiceWithPluginHost

internal/cmd/run.go:35–72  ·  view source on GitHub ↗

StartServiceWithPluginHost builds and runs the proxy service with a shared plugin host.

(cfg *config.Config, configPath string, localPassword string, host *pluginhost.Host)

Source from the content-addressed store, hash-verified

33
34// StartServiceWithPluginHost builds and runs the proxy service with a shared plugin host.
35func 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.
75func StartExampleAPIKeyWarningServer(cfg *config.Config, configPath string, keys []string) {

Callers 2

mainFunction · 0.92
StartServiceFunction · 0.85

Calls 11

NewBuilderFunction · 0.92
WithKeepAliveEndpointFunction · 0.92
startBridgeFunction · 0.85
WithHooksMethod · 0.80
WithConfigPathMethod · 0.80
WithConfigMethod · 0.80
WithPluginHostMethod · 0.80
WithServerOptionsMethod · 0.80
BuildMethod · 0.80
RunMethod · 0.80

Tested by

no test coverage detected