MCPcopy Create free account
hub / github.com/0xUnixIO/pulse / Handle

Method Handle

internal/nodeagent/dispatch.go:47–198  ·  view source on GitHub ↗

Handle 实现 Dispatcher。

(ctx context.Context, method string, body json.RawMessage)

Source from the content-addressed store, hash-verified

45
46// Handle 实现 Dispatcher。
47func (d *APIDispatcher) Handle(ctx context.Context, method string, body json.RawMessage) (json.RawMessage, error) {
48 switch method {
49 // ── 流式 method ──────────────────────────────────────────────
50 case "LogsStream":
51 return nil, d.handleLogsStream(ctx)
52 case "TracerouteStream":
53 var req nodes.TracerouteRequest
54 if len(body) > 0 {
55 if err := json.Unmarshal(body, &req); err != nil {
56 return nil, fmt.Errorf("decode TracerouteStream body: %w", err)
57 }
58 }
59 return nil, d.handleTracerouteStream(ctx, req)
60
61 // ── runtime / 状态 ──
62 case "Runtime":
63 return marshal(d.api.DoRuntime(ctx))
64 case "Status":
65 return marshal(d.api.DoStatus())
66 case "Config":
67 return marshal(d.api.DoConfig())
68 case "Logs":
69 return marshal(d.api.DoLogs())
70 case "AccessLogs":
71 return marshal(d.api.DoAccessLogs())
72
73 case "Usage":
74 var req struct {
75 Reset bool `json:"reset"`
76 }
77 if len(body) > 0 {
78 if err := json.Unmarshal(body, &req); err != nil {
79 return nil, fmt.Errorf("decode Usage body: %w", err)
80 }
81 }
82 return marshal(d.api.DoUsage(req.Reset))
83
84 // ── 进程控制 ──
85 case "Start":
86 var req nodes.ConfigRequest
87 if err := json.Unmarshal(body, &req); err != nil {
88 return nil, fmt.Errorf("decode Start body: %w", err)
89 }
90 st, err := d.api.DoStart(req.Config, "")
91 if err != nil {
92 return nil, err
93 }
94 return marshal(st)
95 case "Stop":
96 st, err := d.api.DoStop()
97 if err != nil {
98 return nil, err
99 }
100 return marshal(st)
101 case "Restart":
102 var req nodes.ConfigRequest
103 if err := json.Unmarshal(body, &req); err != nil {
104 return nil, fmt.Errorf("decode Restart body: %w", err)

Calls 15

handleLogsStreamMethod · 0.95
marshalFunction · 0.85
DoRuntimeMethod · 0.80
DoStatusMethod · 0.80
DoConfigMethod · 0.80
DoLogsMethod · 0.80
DoAccessLogsMethod · 0.80
DoStartMethod · 0.80
DoStopMethod · 0.80
DoRestartMethod · 0.80
DoAddUserMethod · 0.80