-
Notifications
You must be signed in to change notification settings - Fork 0
/
id.go
47 lines (36 loc) · 1.09 KB
/
id.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
package link
// ID is a self-describing identification interface.
type ID interface {
// IsZero returns true if id is zero value.
IsZero() bool
// Parent returns the direct parent of id.
// If id is zero or root, then parent is zero.
Parent() ID
// Index returns the index of id in the parant.
// The index of root id is 0.
Index() (index uint64)
// Child returns the derived child id according to the given index.
Child(index uint64) (child ID)
// IsRoot returns true if id is a root id.
IsRoot() bool
// Root returns the root of id.
Root() (root ID)
// Chain returns the id derivation chain.
// The order of chain from root to id.
// chain := []ID{root, ..., parent, id}
Chain() (chain []ID)
// Deep returns the number of parents in the id derivation chain.
// The deep of root id is 0.
Deep() (deep int)
// Equal reports whether id and xid represent the same id.
Equal(xid ID) bool
// String returns string expression of id.
String() string
}
// Must returns an id if err is nil and panics otherwise.
func Must(id ID, err error) ID {
if err != nil {
panic(err)
}
return id
}