Documentation ¶
Overview ¶
Package syntax provides types for identifiers and other string formats.
These are primarily simple string alias types for parsing or verifying protocol-level syntax of identifiers, not routines for things like resolution or verification against application policies.
Index ¶
- Constants
- Variables
- func Base32Sort() *base32.Encoding
- func ParseDatetimeTime(raw string) (time.Time, error)
- type ATURI
- type AtIdentifier
- func (n AtIdentifier) AsDID() (DID, error)
- func (n AtIdentifier) AsHandle() (Handle, error)
- func (n AtIdentifier) IsDID() bool
- func (n AtIdentifier) IsHandle() bool
- func (a AtIdentifier) MarshalText() ([]byte, error)
- func (n AtIdentifier) Normalize() AtIdentifier
- func (n AtIdentifier) String() string
- func (a *AtIdentifier) UnmarshalText(text []byte) error
- type CID
- type DID
- type Datetime
- type Handle
- func (h Handle) AllowedTLD() bool
- func (h Handle) AtIdentifier() AtIdentifier
- func (h Handle) IsInvalidHandle() bool
- func (h Handle) MarshalText() ([]byte, error)
- func (h Handle) Normalize() Handle
- func (h Handle) String() string
- func (h Handle) TLD() string
- func (h *Handle) UnmarshalText(text []byte) error
- type Language
- type NSID
- type RecordKey
- type TID
- type TIDClock
- type URI
Constants ¶
const ( // Preferred atproto Datetime string syntax, for use with [time.Format]. // // Note that *parsing* syntax is more flexible. AtprotoDatetimeLayout = "2006-01-02T15:04:05.999Z" )
const (
Base32SortAlphabet = "234567abcdefghijklmnopqrstuvwxyz"
)
Variables ¶
var ( // special handle string constant indicating that handle resolution failed HandleInvalid = Handle("handle.invalid") )
Functions ¶
func Base32Sort ¶
Types ¶
type ATURI ¶
type ATURI string
String type which represents a syntaxtually valid AT URI, as would pass Lexicon syntax validation for the 'at-uri' field (no query or fragment parts)
Always use ParseATURI instead of wrapping strings directly, especially when working with input.
Syntax specification: https://atproto.com/specs/at-uri-scheme
func ParseATURI ¶
func (ATURI) Authority ¶
func (n ATURI) Authority() AtIdentifier
Every valid ATURI has a valid AtIdentifier in the authority position.
If this ATURI is malformed, returns empty
func (ATURI) Collection ¶
Returns a valid NSID if there is one in the appropriate part of the path, otherwise empty.
func (ATURI) MarshalText ¶
func (ATURI) Path ¶
Returns path segment, without leading slash, as would be used in an atproto repository key. Or empty string if there is no path.
func (*ATURI) UnmarshalText ¶
type AtIdentifier ¶
type AtIdentifier struct {
Inner interface{}
}
func ParseAtIdentifier ¶
func ParseAtIdentifier(raw string) (*AtIdentifier, error)
func (AtIdentifier) AsDID ¶
func (n AtIdentifier) AsDID() (DID, error)
func (AtIdentifier) AsHandle ¶
func (n AtIdentifier) AsHandle() (Handle, error)
func (AtIdentifier) IsDID ¶
func (n AtIdentifier) IsDID() bool
func (AtIdentifier) IsHandle ¶
func (n AtIdentifier) IsHandle() bool
func (AtIdentifier) MarshalText ¶
func (a AtIdentifier) MarshalText() ([]byte, error)
func (AtIdentifier) Normalize ¶
func (n AtIdentifier) Normalize() AtIdentifier
func (AtIdentifier) String ¶
func (n AtIdentifier) String() string
func (*AtIdentifier) UnmarshalText ¶
func (a *AtIdentifier) UnmarshalText(text []byte) error
type CID ¶
type CID string
Represents a CIDv1 in string format, as would pass Lexicon syntax validation.
You usually want to use the github.com/ipfs/go-cid package and type when working with CIDs ("Links") in atproto. This specific type (syntax.CID) is an informal/incomplete helper specifically for doing fast string verification or pass-through without parsing, re-serialization, or normalization.
Always use ParseCID instead of wrapping strings directly, especially when working with network input.
func (CID) MarshalText ¶
func (*CID) UnmarshalText ¶
type DID ¶
type DID string
Represents a syntaxtually valid DID identifier, as would pass Lexicon syntax validation.
Always use ParseDID instead of wrapping strings directly, especially when working with input.
Syntax specification: https://atproto.com/specs/did
func (DID) AtIdentifier ¶
func (d DID) AtIdentifier() AtIdentifier
func (DID) MarshalText ¶
func (DID) Method ¶
The "method" part of the DID, between the 'did:' prefix and the final identifier segment, normalized to lower-case.
func (*DID) UnmarshalText ¶
type Datetime ¶
type Datetime string
Represents the a Datetime in string format, as would pass Lexicon syntax validation: the intersection of RFC-3339 and ISO-8601 syntax.
Always use ParseDatetime instead of wrapping strings directly, especially when working with network input.
Syntax is specified at: https://atproto.com/specs/lexicon#datetime
func DatetimeNow ¶
func DatetimeNow() Datetime
Creates a new valid Datetime string matching the current time, in preferred syntax.
func ParseDatetime ¶
func ParseDatetimeLenient ¶
func (Datetime) MarshalText ¶
func (Datetime) Time ¶
Parses the Datetime string in to a golang time.Time.
This method assumes that ParseDatetime was used to create the Datetime, which already verified parsing, and thus that time.Parse will always succeed. In the event of an error, zero/nil will be returned.
func (*Datetime) UnmarshalText ¶
type Handle ¶
type Handle string
String type which represents a syntaxtually valid handle identifier, as would pass Lexicon syntax validation.
Always use ParseHandle instead of wrapping strings directly, especially when working with input.
Syntax specification: https://atproto.com/specs/handle
func ParseHandle ¶
func (Handle) AllowedTLD ¶
Some top-level domains (TLDs) are disallowed for registration across the atproto ecosystem. The *syntax* is valid, but these should never be considered acceptable handles for account registration or linking.
The reserved '.test' TLD is allowed, for testing and development. It is expected that '.test' domain resolution will fail in a real-world network.
func (Handle) AtIdentifier ¶
func (h Handle) AtIdentifier() AtIdentifier
func (Handle) IsInvalidHandle ¶
Is this the special "handle.invalid" handle?
func (Handle) MarshalText ¶
func (*Handle) UnmarshalText ¶
type Language ¶
type Language string
Represents a Language specifier in string format, as would pass Lexicon syntax validation.
Always use ParseLanguage instead of wrapping strings directly, especially when working with network input.
The syntax is BCP-47. This is a partial/naive parsing implementation, designed for fast validation and exact-string passthrough with no normaliztion. For actually working with BCP-47 language specifiers in atproto code bases, we recommend the golang.org/x/text/language package.
func ParseLanguage ¶
func (Language) MarshalText ¶
func (*Language) UnmarshalText ¶
type NSID ¶
type NSID string
String type which represents a syntaxtually valid Namespace Identifier (NSID), as would pass Lexicon syntax validation.
Always use ParseNSID instead of wrapping strings directly, especially when working with input.
Syntax specification: https://atproto.com/specs/nsid
func (NSID) Authority ¶
Authority domain name, in regular DNS order, not reversed order, normalized to lower-case.
func (NSID) MarshalText ¶
func (*NSID) UnmarshalText ¶
type RecordKey ¶
type RecordKey string
String type which represents a syntaxtually valid RecordKey identifier, as could be included in an AT URI
Always use ParseRecordKey instead of wrapping strings directly, especially when working with input.
Syntax specification: https://atproto.com/specs/record-key
func ParseRecordKey ¶
func (RecordKey) MarshalText ¶
func (*RecordKey) UnmarshalText ¶
type TID ¶
type TID string
Represents a TID in string format, as would pass Lexicon syntax validation.
Always use ParseTID instead of wrapping strings directly, especially when working with network input.
Syntax specification: https://atproto.com/specs/record-key
func NewTIDFromInteger ¶
func NewTIDFromTime ¶
Constructs a new TID from a time.Time and clock ID value
func NewTIDNow ¶
Naive (unsafe) one-off TID generation with the current time.
You should usually use a TIDClock to ensure monotonic output.
func (TID) MarshalText ¶
func (*TID) UnmarshalText ¶
type TIDClock ¶
type TIDClock struct { ClockID uint // contains filtered or unexported fields }
TID generator, which keeps state to ensure TID values always monotonically increase.
Uses sync.Mutex, so may block briefly but safe for concurrent use.
func NewTIDClock ¶
type URI ¶
type URI string
Represents an arbitrary URI in string format, as would pass Lexicon syntax validation.
The syntax is minimal and permissive, designed for fast verification and exact-string passthrough, not schema-specific parsing or validation. For example, will not validate AT-URI or DID strings.
Always use ParseURI instead of wrapping strings directly, especially when working with network input.