-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtaguri.go
70 lines (65 loc) · 1.83 KB
/
taguri.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package taguri
// TagURI represents a tag-URI.
//
// Some example tag-URIs include:
//
// tag:example.com,2024-03-01:note-q744cpgu2s3n7x3
//
// tag:joeblow@,2024-03-01:0x8b52d56e53ca7a4fa86ae860888c6611
//
// tag:blogger.com,1999:blog-555
//
// tag:my-ids.com,2001-09-15:JaneDoe:presentations:UBath2004-05-19
//
// Tag-URIs are a method of creating unique identifiers.
//
// From IETF RFC-4151 —
//
// “A tag is a type of Uniform Resource Identifier (URI) [1] designed to meet the following requirements:”
//
// “1. Identifiers are likely to be unique across space and time, and come from a practically inexhaustible supply.”
//
// “2. Identifiers are relatively convenient for humans to mint (create), read, type, remember etc.”
//
// “3. No central registration is necessary, at least for holders of domain names or email addresses; and there is negligible cost to mint each new identifier.”
//
// “4. The identifiers are independent of any particular resolution scheme.”
//
type TagURI struct {
AuthorityName string
Date string
Specific string
Fragment string
}
// String returns the (serialized) tag-URI, based on the data in the 'receiver'.
//
// For example, this:
//
// var tag taguri.TagURI = taguri.TagURI{
// AuthorityName: "example.com",
// Date: "2024-03-08",
// Specific: "note-EY7NjqnYtc",
// }
//
// // ...
//
// fmt.Println(tag.String())
//
// Would output:
//
// tag:example.com,2024-03-08:note-EY7NjqnYtc
func (receiver TagURI) String() string {
var buffer [256]byte
var p []byte = buffer[0:0]
p = append(p, "tag:"...)
p = append(p, receiver.AuthorityName...)
p = append(p, ',')
p = append(p, receiver.Date...)
p = append(p, ':')
p = append(p, receiver.Specific...)
if "" != receiver.Fragment {
p = append(p, '#')
p = append(p, receiver.Fragment...)
}
return string(p)
}