Documentation
¶
Index ¶
- type FediverseID
- func (receiver FediverseID) AcctURI() string
- func (receiver *FediverseID) ChainSetHost(value string) *FediverseID
- func (receiver *FediverseID) ChainSetName(value string) *FediverseID
- func (receiver *FediverseID) FediverseID() FediverseID
- func (receiver FediverseID) GoString() string
- func (receiver FediverseID) Host() (string, bool)
- func (receiver FediverseID) HostElse(alt string) string
- func (receiver FediverseID) MarshalText() ([]byte, error)
- func (receiver FediverseID) Name() (string, bool)
- func (receiver FediverseID) NameElse(alt string) string
- func (receiver FediverseID) Serialize() (string, error)
- func (receiver *FediverseID) SetHost(value string)
- func (receiver *FediverseID) SetName(value string)
- func (receiver FediverseID) String() string
- func (receiver *FediverseID) UnmarshalText(text []byte) error
- func (receiver *FediverseID) Unserialize(text string) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FediverseID ¶
type FediverseID struct {
// contains filtered or unexported fields
}
FediverseID represents a Fediverse-ID.
A (serialized) Fediverse-ID looks similar to this:
@joeblow@host.example
To create a FediverseID use CreateFediverseID or EmptyFediverseID.
To create a pointer to a FediverseID use NewFediverseID or new(fediverseid.FediverseID).
To create a FediverseID from a serialized fediverse-id use ParseFediverseIDBytes or ParseFediverseIDString.
To serialize a FediverseID (to a string) use FediverseID.MarshalText or FediverseID.String.
Example (CreateFediverseID) ¶
const name string = "joeblow" const host string = "host.example" var fid fediverseid.FediverseID = fediverseid.CreateFediverseID(name, host) fmt.Printf("fediverse-id: %s", fid)
Output: fediverse-id: @joeblow@host.example
Example (EmptyFediverseID) ¶
var fid fediverseid.FediverseID = fediverseid.EmptyFediverseID() fmt.Printf("fediverse-id (golang code): %#v", fid)
Output: fediverse-id (golang code): fediverseid.EmptyFediverseID()
Example (NewFediverseID) ¶
const name string = "joeblow" const host string = "host.example" var fid *fediverseid.FediverseID = fediverseid.NewFediverseID(name, host) fmt.Printf("fediverse-id: %s", fid)
Output: fediverse-id: @joeblow@host.example
Example (NewFediverseID_keyword) ¶
const name string = "joeblow" const host string = "host.example" var fid *fediverseid.FediverseID = new(fediverseid.FediverseID).ChainSetName(name).ChainSetHost(host) fmt.Printf("fediverse-id: %s", fid)
Output: fediverse-id: @joeblow@host.example
Example (ParseFediverseIDBytes) ¶
var bytes []byte = []byte("@joeblow@host.example") var fid fediverseid.FediverseID var err error fid, err = fediverseid.ParseFediverseIDBytes(bytes) if nil != err { fmt.Printf("ERROR: problem parsing (serialized) fediverse-id %q: %s", bytes, err) return } fmt.Printf("fediverse-id name: %s\n", fid.NameElse("")) fmt.Printf("fediverse-id host: %s\n", fid.HostElse(""))
Output: fediverse-id name: joeblow fediverse-id host: host.example
Example (ParseFediverseIDString) ¶
var str string = "@joeblow@host.example" var fid fediverseid.FediverseID var err error fid, err = fediverseid.ParseFediverseIDString(str) if nil != err { fmt.Printf("ERROR: problem parsing (serialized) fediverse-id %q: %s", str, err) return } fmt.Printf("fediverse-id name: %s\n", fid.NameElse("")) fmt.Printf("fediverse-id host: %s\n", fid.HostElse(""))
Output: fediverse-id name: joeblow fediverse-id host: host.example
func CreateFediverseID ¶
func CreateFediverseID(name string, host string) FediverseID
CreateFediverseID creates a FediverseID.
For example:
var name string = "joeblow" var host string = "host.example" fid := fediverseid.CreateFediverseID(name, host)
Example ¶
const name string = "joeblow" const host string = "host.example" fid := fediverseid.CreateFediverseID(name, host) var fediverseID string = fid.String() fmt.Printf("fediverse-id: %s", fediverseID)
Output: fediverse-id: @joeblow@host.example
func EmptyFediverseID ¶
func EmptyFediverseID() FediverseID
EmptyFediverseID returns an empty FediverseID.
For example:
fid := fediverseid.EmptyFediverseID()
func NewFediverseID ¶
func NewFediverseID(name string, host string) *FediverseID
NewFediverseID returns a new *FediverseID with the `name` and `host` specified.
For example:
var name string = "joeblow" var host string = "host.example" fid := fediverseid.NewFediverseID(name, host)
func ParseFediverseIDBytes ¶
func ParseFediverseIDBytes(id []byte) (FediverseID, error)
ParseFediverseIDBytes parses a []byte and (if valid) returns a FediverseID. If not valid, returns an error.
For example:
var value []byte = []byte("@joeblow@host.example") fid, err := fediverseid.ParseFediverseIDBytes(value)
See also: ParseFediverseIDString
func ParseFediverseIDString ¶
func ParseFediverseIDString(id string) (FediverseID, error)
ParseFediverseIDString parses a string and (if valid) returns a FediverseID. If not valid, returns an error.
For example:
var value string = "@joeblow@host.example" fid, err := fediverseid.ParseFediverseIDString(value)
See also: ParseFediverseIDBytes
func (FediverseID) AcctURI ¶
func (receiver FediverseID) AcctURI() string
AcctURI returns the acct-uri equivalent of the FediverseID. AcctURI returns an empty string ("") if the receiver isn't a valid Fediverse-ID.
Example ¶
const name string = "joeblow" const host string = "host.example" fid := fediverseid.CreateFediverseID(name, host) var fediverseID string = fid.String() var acctURI string = fid.AcctURI() // <--------- fmt.Printf("fediverse-id: %s\n", fediverseID) fmt.Printf("acct-uri: %s\n", acctURI)
Output: fediverse-id: @joeblow@host.example acct-uri: acct:joeblow@host.example
func (*FediverseID) ChainSetHost ¶
func (receiver *FediverseID) ChainSetHost(value string) *FediverseID
ChainSetHost sets the (raw) 'host' of the FediverseID, and returns the receiver.
This is useful for chaining.
func (*FediverseID) ChainSetName ¶
func (receiver *FediverseID) ChainSetName(value string) *FediverseID
ChainSetName sets the (raw) 'name' of the FediverseID, and returns the receiver.
This is useful for chaining.
func (*FediverseID) FediverseID ¶
func (receiver *FediverseID) FediverseID() FediverseID
FediverseID turns a *FediverseID (i.e., a pointer to a FediverseID) back into a FediverseID.
For example:
var fid fediveseid.FediverseID = fediveseid.EmptyFediverseID().ChainSetHost("example.com").FediverseID()
func (FediverseID) GoString ¶
func (receiver FediverseID) GoString() string
GoString returns Go code (as a string) that could be used to create this FediverseID.
GoString also makes FediverseID fit the fmt.GoStringer interface. (Which is used by fmt.Errorf, fmt.Fprint, fmt.Fprintf, fmt.Fprintln, fmt.Print, fmt.Printf, fmt.Println, and other similar functions, with the "%#v" format.)
func (FediverseID) Host ¶
func (receiver FediverseID) Host() (string, bool)
Host returns the (raw) 'host' of a Fediverse-ID.
func (FediverseID) HostElse ¶
func (receiver FediverseID) HostElse(alt string) string
HostElse returns the (raw) 'host' of a Fediverse-ID if defined, else returns 'alt'.
func (FediverseID) MarshalText ¶
func (receiver FediverseID) MarshalText() ([]byte, error)
MarshalText returns the (serialized) Fediverse-ID, if valid. Else returns an error.
MarshalText is similar to FediverseID.Serialize except that is returns a []byte rather than a string.
MarshalText is also similar to FediverseID.String except that it returns a []byte and an error if it is invalid.
MarshalText also makes FediverseID fit the encoding.TextMarshaler interface. And thus, among other things, is an alternative to [json.Marshaler].
func (FediverseID) Name ¶
func (receiver FediverseID) Name() (string, bool)
Name returns the (raw) 'name' of a Fediverse-ID.
func (FediverseID) NameElse ¶
func (receiver FediverseID) NameElse(alt string) string
NameElse returns the (raw) 'name' of a Fediverse-ID if defined, else returns 'alt'.
func (FediverseID) Serialize ¶
func (receiver FediverseID) Serialize() (string, error)
Serialize returns the (serialized) Fediverse-ID, if valid. Else returns an error.
Serialize is similar to FediverseID.String except that it returns an error if it is invalid.
Serialize is also similar to FediverseID.MarshalText except that is returns a string rather than a []byte.
func (*FediverseID) SetHost ¶
func (receiver *FediverseID) SetHost(value string)
SetHost sets the (raw) 'host' of the FediverseID.
func (*FediverseID) SetName ¶
func (receiver *FediverseID) SetName(value string)
SetName sets the (raw) 'name' of the FediverseID.
func (FediverseID) String ¶
func (receiver FediverseID) String() string
String returns the (serialized) Fediverse-ID, if valid. Else returns an empty string.
String also makes FediverseID fit the fmt.Stringer interface. (Which is used by fmt.Errorf, fmt.Fprint, fmt.Fprintf, fmt.Fprintln, fmt.Print, fmt.Printf, fmt.Println, and other similar functions.)
See also: FediverseID.Serialize.
Example ¶
const name string = "joeblow" const host string = "host.example" fid := fediverseid.CreateFediverseID(name, host) var fediverseID string = fid.String() // <--------- fmt.Printf("fediverse-id: %s", fediverseID)
Output: fediverse-id: @joeblow@host.example
func (*FediverseID) UnmarshalText ¶
func (receiver *FediverseID) UnmarshalText(text []byte) error
UnmarshalText unserializes Fediverse-ID, if valid, and sets the value of the receiver to it. Else returns an error.
UnmarshalText is similar to [Unserialize] except that it takes a []byte parameter rather than a string parameter.
UnmarshalText is similar to ParseFediverseIDBytes, except UnmarshalText is a method of FediverseID, where ParseFediverseIDBytes is a standalone function. And because UnmarshalText is similar to ParseFediverseIDBytes, it is also similar to ParseFediverseIDString.
UnmarshalText also makes FediverseID fit the encoding.TextUnmarshaler interface. And thus, among other things, is an alternative to [json.Unmarshaler].
func (*FediverseID) Unserialize ¶
func (receiver *FediverseID) Unserialize(text string) error
Unserialize unserializes Fediverse-ID, if valid, and sets the value of the receiver to it. Else returns an error.
Unserialize is similar to [UnmarshalText] except that it takes a string parameter rather than a []byte parameter.
Unserialize is similar to ParseFediverseIDString, except Unserialize is a method of FediverseID, where ParseFediverseIDString is a standalone function. And because Unserialize is similar to ParseFediverseIDString, it is also similar to ParseFediverseIDBytes.