AddResourceTemplate adds a [ResourceTemplate] to the server, or replaces one with the same URI. AddResourceTemplate panics if a URI template is invalid or not absolute (has an empty scheme).
(t *ResourceTemplate, h ResourceHandler)
| 536 | // AddResourceTemplate adds a [ResourceTemplate] to the server, or replaces one with the same URI. |
| 537 | // AddResourceTemplate panics if a URI template is invalid or not absolute (has an empty scheme). |
| 538 | func (s *Server) AddResourceTemplate(t *ResourceTemplate, h ResourceHandler) { |
| 539 | s.changeAndNotify(notificationResourceListChanged, |
| 540 | func() bool { |
| 541 | // Validate the URI template syntax |
| 542 | _, err := uritemplate.New(t.URITemplate) |
| 543 | if err != nil { |
| 544 | panic(fmt.Errorf("URI template %q is invalid: %w", t.URITemplate, err)) |
| 545 | } |
| 546 | s.resourceTemplates.add(&serverResourceTemplate{t, h}) |
| 547 | return true |
| 548 | }) |
| 549 | } |
| 550 | |
| 551 | // RemoveResourceTemplates removes the resource templates with the given URI templates. |
| 552 | // It is not an error to remove a nonexistent resource. |