SendNotification sends a notification to the client. This method sends a JSON-RPC 2.0 notification (a request without an ID) to the client. Notifications are one-way messages that do not expect a response. The server uses this method to push information to the client asynchronously, such as diagno
(method string, params interface{})
| 451 | // If params is nil, an empty notification without params will be sent. |
| 452 | // If marshaling params fails, the error is logged but no notification is sent. |
| 453 | func (s *Server) SendNotification(method string, params interface{}) { |
| 454 | notif := Notification{ |
| 455 | JSONRPC: "2.0", |
| 456 | Method: method, |
| 457 | } |
| 458 | if params != nil { |
| 459 | data, err := json.Marshal(params) |
| 460 | if err != nil { |
| 461 | s.logger.Printf("Failed to marshal notification params for %s: %v", method, err) |
| 462 | return |
| 463 | } |
| 464 | notif.Params = json.RawMessage(data) |
| 465 | } |
| 466 | s.sendMessage(notif) |
| 467 | } |
| 468 | |
| 469 | // sendMessage sends a message to the client |
| 470 | func (s *Server) sendMessage(msg interface{}) { |
no test coverage detected