share

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package share defines the bounded, transport-free model that mobile share and keyboard extensions use to hand text, links, and attachment references to their containing application.

The package owns normalization and limits only. It never reads a native extension context, copies a file, selects a container, shows UI, records an event, launches an application, or applies a product protocol. Native implementations ship beside this contract in res/system/ios and res/system/android, and a caller supplies every destination directory.

Index

Constants

View Source
const (
	// DefaultMaxItems bounds the number of contributions in one share event.
	DefaultMaxItems = 32
	// MaxItems is the library ceiling for MaxItems.
	MaxItems = 128
	// DefaultMaxBytes bounds attachment payload bytes plus declared sizes.
	DefaultMaxBytes int64 = 16 << 20
	// MaxBytes is the library ceiling for MaxBytes.
	MaxBytes int64 = 64 << 20
	// DefaultMaxTextBytes bounds text and subject content.
	DefaultMaxTextBytes = 64 << 10
	// MaxTextBytes is the library ceiling for MaxTextBytes.
	MaxTextBytes = 1 << 20
	// MaxURLLength bounds one normalized link.
	MaxURLLength = 8192
	// MaxNameLength bounds one attachment file name.
	MaxNameLength = 255
	// MaxMIMETypeLength bounds one attachment media type.
	MaxMIMETypeLength = 255
)

Variables

View Source
var (
	// ErrInvalid reports malformed or contradictory share input.
	ErrInvalid = errors.New("invalid share input")
	// ErrLimit reports input beyond a caller-selected bound.
	ErrLimit = errors.New("share limit exceeded")
)

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Name     string `json:"name"`
	MIMEType string `json:"mime_type"`
	Size     int64  `json:"size"`
	Data     []byte `json:"data,omitempty"`
	Path     string `json:"path,omitempty"`
}

Attachment is one shared file. Exactly one of Data and Path carries the content: Data is an already-bounded copy, Path is a caller-owned location outside the extension container. Size is the byte count of the content and must agree with Data when both are present.

type Item

type Item struct {
	Subject     string       `json:"subject,omitempty"`
	Text        string       `json:"text,omitempty"`
	URLs        []string     `json:"urls,omitempty"`
	Attachments []Attachment `json:"attachments,omitempty"`
}

Item is one contribution from a native share source. Subject is optional preview text supplied by the sharing application; it is not a destination or an approval decision.

type Limits

type Limits struct {
	MaxItems     int   `json:"max_items"`
	MaxBytes     int64 `json:"max_bytes"`
	MaxTextBytes int   `json:"max_text_bytes"`
	MaxURLLength int   `json:"max_url_length"`
}

Limits are fixed by the embedding application before a native extension loads any item. Zero fields select the defaults; every field has a library ceiling so a caller cannot disable bounding.

func (Limits) Normalize

func (l Limits) Normalize() (Limits, error)

Normalize resolves defaults and rejects limits beyond the library ceilings.

type Payload

type Payload struct {
	Subject     string       `json:"subject,omitempty"`
	Text        string       `json:"text,omitempty"`
	URLs        []string     `json:"urls"`
	Attachments []Attachment `json:"attachments"`
	ByteCount   int64        `json:"byte_count"`
}

Payload is the normalized, deduplicated result. ByteCount covers attachment content only; text has its own bound. The embedding application owns the destination and any further transport.

func Normalize

func Normalize(items []Item, limits Limits) (Payload, error)

Normalize validates and merges native items into one bounded payload. Exact duplicate texts, links, and attachments collapse to their first occurrence, so a provider that repeats an item cannot multiply an event. Conflicting duplicates such as two different attachments with one name are preserved with distinct names only when the caller can tell them apart; otherwise the second is rejected.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL