AddResource adds a [Resource] to the server, or replaces one with the same URI. AddResource panics if the resource URI is invalid or not absolute (has an empty scheme).
(r *Resource, h ResourceHandler)
| 517 | // AddResource adds a [Resource] to the server, or replaces one with the same URI. |
| 518 | // AddResource panics if the resource URI is invalid or not absolute (has an empty scheme). |
| 519 | func (s *Server) AddResource(r *Resource, h ResourceHandler) { |
| 520 | s.changeAndNotify(notificationResourceListChanged, |
| 521 | func() bool { |
| 522 | if _, err := url.Parse(r.URI); err != nil { |
| 523 | panic(err) // url.Parse includes the URI in the error |
| 524 | } |
| 525 | s.resources.add(&serverResource{r, h}) |
| 526 | return true |
| 527 | }) |
| 528 | } |
| 529 | |
| 530 | // RemoveResources removes the resources with the given URIs. |
| 531 | // It is not an error to remove a nonexistent resource. |