package mcpimport ()// ResourceOption is a function that configures a Resource.// It provides a flexible way to set various properties of a Resource using the functional options pattern.typeResourceOptionfunc(*Resource)// NewResource creates a new Resource with the given URI, name and options.// The resource will be configured based on the provided options.// Options are applied in order, allowing for flexible resource configuration.func ( string, string, ...ResourceOption) Resource { := Resource{URI: ,Name: , }for , := range { (&) }return}// WithResourceDescription adds a description to the Resource.// The description should provide a clear, human-readable explanation of what the resource represents.func ( string) ResourceOption {returnfunc( *Resource) { .Description = }}// WithMIMEType sets the MIME type for the Resource.// This should indicate the format of the resource's contents.func ( string) ResourceOption {returnfunc( *Resource) { .MIMEType = }}// WithAnnotations returns a ResourceOption that sets the resource's Annotations fields.// It initializes Annotations if nil, sets Audience to the provided slice,// stores Priority as a pointer to the provided value, and sets LastModified to the provided timestamp.func ( []Role, float64, string) ResourceOption {returnfunc( *Resource) {if .Annotations == nil { .Annotations = &Annotations{} } .Annotations.Audience = .Annotations.Priority = & .Annotations.LastModified = }}// WithLastModified returns a ResourceOption that sets the resource's Annotations.LastModified// to the provided timestamp. If the resource's Annotations is nil, it will be initialized.// The timestamp is expected to be an ISO 8601 (RFC3339) formatted string (e.g., "2025-01-12T15:00:58Z").func ( string) ResourceOption {returnfunc( *Resource) {if .Annotations == nil { .Annotations = &Annotations{} } .Annotations.LastModified = }}// ResourceTemplateOption is a function that configures a ResourceTemplate.// It provides a flexible way to set various properties of a ResourceTemplate using the functional options pattern.typeResourceTemplateOptionfunc(*ResourceTemplate)// NewResourceTemplate creates a new ResourceTemplate with the given URI template, name and options.// The template will be configured based on the provided options.// Options are applied in order, allowing for flexible template configuration.func ( string, string, ...ResourceTemplateOption) ResourceTemplate { := ResourceTemplate{URITemplate: &URITemplate{Template: uritemplate.MustNew()},Name: , }for , := range { (&) }return}// WithTemplateDescription adds a description to the ResourceTemplate.// The description should provide a clear, human-readable explanation of what resources this template represents.func ( string) ResourceTemplateOption {returnfunc( *ResourceTemplate) { .Description = }}// WithTemplateMIMEType sets the MIME type for the ResourceTemplate.// This should only be set if all resources matching this template will have the same type.func ( string) ResourceTemplateOption {returnfunc( *ResourceTemplate) { .MIMEType = }}// WithTemplateAnnotations returns a ResourceTemplateOption that sets the template's// Annotations field, initializing it if nil, and setting Audience, Priority, and LastModified.func ( []Role, float64, string) ResourceTemplateOption {returnfunc( *ResourceTemplate) {if .Annotations == nil { .Annotations = &Annotations{} } .Annotations.Audience = .Annotations.Priority = & .Annotations.LastModified = }}// ValidateISO8601Timestamp verifies that timestamp is a valid ISO 8601 timestamp// using the RFC3339 layout. An empty string is considered valid. It returns nil// when the timestamp is valid, or the parsing error when it is not.func ( string) error {if == "" {returnnil// Empty is valid (optional field) }// Use time.RFC3339 for ISO 8601 compatibility , := time.Parse(time.RFC3339, )return}// WithResourceIcons adds icons to the Resource.// Icons provide visual identifiers for the resource.func ( ...Icon) ResourceOption {returnfunc( *Resource) { .Icons = }}// WithTemplateIcons adds icons to the ResourceTemplate.// Icons provide visual identifiers for the resource template.func ( ...Icon) ResourceTemplateOption {returnfunc( *ResourceTemplate) { .Icons = }}
The pages are generated with Goldsv0.8.4. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.