Documentation
¶
Overview ¶
Package media defines the serializable Media container shared by every modality that accepts non-text payloads.
Use NewBytes for owned inline content, NewURI for an absolute external URI, or NewReference for a provider-native identifier. Source is a tagged union: exactly one source must match its Kind. Constructors and JSON decoding enforce that invariant and validate the MIME type.
Example ¶
package main
import (
"fmt"
"github.com/Tangerg/scope/core/media"
)
func main() {
attachment, err := media.NewBytes("image/png", []byte("scope"))
if err != nil {
panic(err)
}
attachment.ID = "image-1"
attachment.Name = "scope.png"
fmt.Println(attachment.Source.Kind, len(attachment.Source.Bytes), attachment.Name)
}
Output: bytes 5 scope.png
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type Media ¶
type Media struct {
MIME string `json:"mime"`
Source Source `json:"source"`
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Metadata metadata.Map `json:"metadata,omitzero"`
}
Inline-byte construction snapshots the caller's buffer.
func NewReference ¶
NewReference retains an opaque handle valid only with the provider that issued it.
func NewURI ¶
NewURI leaves content resolution to the provider or client; the URI must be reachable by it.
func (Media) MarshalJSON ¶
func (*Media) UnmarshalJSON ¶
type Source ¶
type Source struct {
Kind SourceKind `json:"kind"`
Bytes []byte `json:"bytes,omitempty"`
URI string `json:"uri,omitempty"`
Ref string `json:"ref,omitempty"`
}
Source is a tagged union. Kind selects exactly one of Bytes, URI, or Ref; all other fields must be empty.
type SourceKind ¶
type SourceKind string
const ( SourceBytes SourceKind = "bytes" SourceURI SourceKind = "uri" SourceReference SourceKind = "reference" )