Documentation
¶
Index ¶
- func Construct(values ...string) string
- func ConstructAndNormalize(values ...string) string
- func Join(domainAuthority string, name string) string
- func JoinAndNormalize(domainAuthority string, name string) string
- func Normalize(value string) string
- func NormalizeDomainAuthority(value string) string
- func Split(value string) (domainAuthority string, name string)
- func SplitAndNormalize(value string) (domainAuthority string, name string)
- func Validate(value string) error
- type NSID
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Construct ¶
Construct creates an NSID (Namespaced Identifier).
The NSID (Namespaced Identifier) is part of BlueSky's AT-Protocol, as defined here: https://atproto.com/specs/nsid
Construct is similar to Join, but is more flexible.
Construct allows the domain-authority to be broken into parts.
Note that the NSID that Construct returns is NOT normalized. Use ConstructAndNormalize to create a normalized NSID.
If you are not sure whether to use Construct or ConstructAndNormalize, use ConstructAndNormalize.
Example ¶
package main
import (
"fmt"
"github.com/reiver/go-nsid"
)
func main() {
nsID := nsid.Construct("org.archive", "video.streaming", "createStream")
fmt.Printf("nsid: %s\n", nsID)
}
Output: nsid: org.archive.video.streaming.createStream
func ConstructAndNormalize ¶
ConstructAndNormalize and similar to Construct but it also normalizes the resulting NSID (Namespaced Identifier).
ConstructAndNormalize creates an NSID (Namespaced Identifier).
The NSID (Namespaced Identifier) is part of BlueSky's AT-Protocol, as defined here: https://atproto.com/specs/nsid
ConstructAndNormalize is similar to Join, but is more flexible.
ConstructAndNormalize allows the domain-authority to be broken into parts.
If you are not sure whether to use Construct or ConstructAndNormalize, use ConstructAndNormalize.
Example ¶
package main
import (
"fmt"
"github.com/reiver/go-nsid"
)
func main() {
nsID := nsid.ConstructAndNormalize("org.archive", "video.streaming", "createStream")
fmt.Printf("nsid: %s\n", nsID)
}
Output: nsid: org.archive.video.streaming.createStream
func Join ¶
Join combines an NSID domain-authority (such as "com.example") with an NSID name (such as "fooBar") to construct an NSID (such as "com.example.fooBar").
The NSID (Namespaced Identifier) is part of BlueSky's AT-Protocol, as defined here: https://atproto.com/specs/nsid
Join more-or-less does the opposite of Split.
Note that the NSID that Join returns is NOT normalized. Use JoinAndNormalize to create a normalized NSID.
Join does not validate the overall resulting NSID. To validate the overall resulting NSID call Validate.
If you are not sure whether to use Join or JoinAndNormalize, use JoinAndNormalize.
Example ¶
package main
import (
"fmt"
"github.com/reiver/go-nsid"
)
func main() {
var domainAuthority string = "com.example"
var name string = "fooBar"
nsID := nsid.Join(domainAuthority, name)
fmt.Printf("domain-authority: %s\n", domainAuthority)
fmt.Printf("name: %s\n", name)
fmt.Printf("nsid: %s\n", nsID)
}
Output: domain-authority: com.example name: fooBar nsid: com.example.fooBar
func JoinAndNormalize ¶
JoinAndNormalize and similar to Join but it also normalizes the resulting NSID (Namespaced Identifier).
The NSID (Namespaced Identifier) is part of BlueSky's AT-Protocol, as defined here: https://atproto.com/specs/nsid
JoinAndNormalize combines an NSID domain-authority (such as "com.example") with an NSID name (such as "fooBar") to construct an NSID (such as "com.example.fooBar").
Join more-or-less does the opposite of Split.
Note that the NSID that Join returns is normalized.
Join does not validate the overall resulting NSID. To validate the overall resulting NSID call Validate.
If you are not sure whether to use Join or JoinAndNormalize, use JoinAndNormalize.
Example ¶
package main
import (
"fmt"
"github.com/reiver/go-nsid"
)
func main() {
var domainAuthority string = "com.example"
var name string = "fooBar"
nsID := nsid.JoinAndNormalize(domainAuthority, name)
fmt.Printf("domain-authority: %s\n", domainAuthority)
fmt.Printf("name: %s\n", name)
fmt.Printf("nsid: %s\n", nsID)
}
Output: domain-authority: com.example name: fooBar nsid: com.example.fooBar
func Normalize ¶
Normalize returns the normalized form of an NSID, as defined in: https://atproto.com/specs/nsid
Normalize does NOT validate the NSID. To validate, call Validate.
An example of a non-normalized NSID domain-authority would be "COM.Example.fooBar". Normalizing that non-normalized NSID domain-authority would result in "com.example.fooBar".
Example ¶
package main
import (
"fmt"
"github.com/reiver/go-nsid"
)
func main() {
var nsID string = "COM.Example.fooBar"
normalized := nsid.Normalize(nsID)
fmt.Printf("original nsid: %s\n", nsID)
fmt.Printf("noramlized nsid: %s\n", normalized)
}
Output: original nsid: COM.Example.fooBar noramlized nsid: com.example.fooBar
func NormalizeDomainAuthority ¶
NormalizeDomainAuthority returns the normalized form of an domain-authority, as defined in: https://atproto.com/specs/nsid
The domain-authority (such as "com.example") is part of an NSID (such as "com.example.fooBar").
In simple language, you can think of an NSID domain-authority as an Internet domain-name written in reverse-order. For example, if the Internet domain-name was "example.com", then the NSID domain-authority would be "com.example".
An example of a non-normalized NSID domain-authority would be "COM.Example". Normalizing that non-normalized NSID domain-authority would result in "com.example".
Note that if you want to normalize a whole NSID rather than just a domain-authority, then instead use Normalize.
Example ¶
package main
import (
"fmt"
"github.com/reiver/go-nsid"
)
func main() {
var domainAuthority string = "COM.Example"
normalized := nsid.NormalizeDomainAuthority(domainAuthority)
fmt.Printf("original domain-authority: %s\n", domainAuthority)
fmt.Printf("noramlized domain-authority: %s\n", normalized)
}
Output: original domain-authority: COM.Example noramlized domain-authority: com.example
func Split ¶
Split returns the domain-authority and name of an NSID, as defined here: https://atproto.com/specs/nsid
Split does NOT normalizes the domain-authority of the NSID that it returns. Use SplitAndNormalize to have the domain-authority normalized.
If you are not sure whether to use Split or [SpliAndNormalize], use SplitAndNormalize.
Example ¶
package main
import (
"fmt"
"github.com/reiver/go-nsid"
)
func main() {
var nsID string = "COM.Example.fooBar"
domainAuthority, name := nsid.Split(nsID)
fmt.Printf("nsid: %s\n", nsID)
fmt.Printf("domain-authority: %s\n", domainAuthority)
fmt.Printf("name: %s\n", name)
}
Output: nsid: COM.Example.fooBar domain-authority: COM.Example name: fooBar
func SplitAndNormalize ¶
Split returns the domain-authority and name of an NSID, as defined here: https://atproto.com/specs/nsid
Split normalizes the domain-authority of the NSID that it returns.
If you are not sure whether to use Split or SpliAndNormalize, use SplitAndNormalize.
Example ¶
package main
import (
"fmt"
"github.com/reiver/go-nsid"
)
func main() {
var nsID string = "COM.Example.fooBar"
domainAuthority, name := nsid.SplitAndNormalize(nsID)
fmt.Printf("nsid: %s\n", nsID)
fmt.Printf("domain-authority: %s\n", domainAuthority)
fmt.Printf("name: %s\n", name)
}
Output: nsid: COM.Example.fooBar domain-authority: com.example name: fooBar
func Validate ¶
Validate returns an error if the NSID is invalid. It returns nil if the NSID is valid.
The validation rules for an NSID are defined here: https://atproto.com/specs/nsid
Example ¶
package main
import (
"fmt"
"github.com/reiver/go-nsid"
)
func main() {
var nsID string = "com.example.foo-bar"
err := nsid.Validate(nsID)
fmt.Printf("nsid: %s\n", nsID)
fmt.Printf("validation error: %s\n", err)
}
Output: nsid: com.example.foo-bar validation error: nsid: character №3 ('-') (U+002D) of name ("foo-bar") of nsid ("com.example.foo-bar") cannot be a hyphen but must instead be an upper-case letter ('A'-'Z'), or lower-case letter ('a'-'z'), or digits ('0'-'9')
Types ¶
type NSID ¶
type NSID string
NSID represents a NSID (Namespaced Identifier).
The NSID (Namespaced Identifier) is part of BlueSky's AT-Protocol, as defined here: https://atproto.com/specs/nsid
func CreateNSID ¶
CreateNSID creates an NSID (Namespaced Identifier).
The NSID (Namespaced Identifier) is part of BlueSky's AT-Protocol, as defined here: https://atproto.com/specs/nsid
func MustCreateNSID ¶
MustCreateNSID is similar to CreateNSID expect it panic()s if thre is an error.
The NSID (Namespaced Identifier) is part of BlueSky's AT-Protocol, as defined here: https://atproto.com/specs/nsid
func (NSID) DomainAuthority ¶
DomainAuthority returns the domain-authority of an NSID.
The NSID (Namespaced Identifier) is part of BlueSky's AT-Protocol, as defined here: https://atproto.com/specs/nsid
func (NSID) Name ¶
Name returns the domain-authority of an NSID.
The NSID (Namespaced Identifier) is part of BlueSky's AT-Protocol, as defined here: https://atproto.com/specs/nsid
func (NSID) Split ¶
Split returns the domain-authority and name of an NSID.
The NSID (Namespaced Identifier) is part of BlueSky's AT-Protocol, as defined here: https://atproto.com/specs/nsid
func (NSID) Validate ¶
Validate returns an error if the NSID is invalid. It returns nil if the NSID is valid.
The NSID (Namespaced Identifier) is part of BlueSky's AT-Protocol, as defined here: https://atproto.com/specs/nsid