@@ -7,24 +7,28 @@ import (
7
7
"tailscale.com/types/key"
8
8
)
9
9
10
+ // NodePublic is a wrapper around a key.NodePublic which represents the
11
+ // Wireguard public key for an agent..
10
12
type NodePublic key.NodePublic
11
13
12
14
func (n NodePublic ) String () string {
13
15
return key .NodePublic (n ).String ()
14
16
}
15
17
18
+ // This is necessary so NodePublic can be serialized in JSON loggers.
16
19
func (n NodePublic ) MarshalJSON () ([]byte , error ) {
17
20
j , err := key .NodePublic (n ).MarshalText ()
18
21
// surround in quotes to make it a JSON string
19
- j = append ([]byte {'"' }, j ... )
20
- j = append (j , '"' )
22
+ j = append ([]byte {'"' }, append (j , '"' )... )
21
23
return j , err
22
24
}
23
25
26
+ // Value is so NodePublic can be inserted into the database.
24
27
func (n NodePublic ) Value () (driver.Value , error ) {
25
28
return key .NodePublic (n ).MarshalText ()
26
29
}
27
30
31
+ // Scan is so NodePublic can be read from the database.
28
32
func (n * NodePublic ) Scan (value interface {}) error {
29
33
switch v := value .(type ) {
30
34
case []byte :
@@ -36,24 +40,28 @@ func (n *NodePublic) Scan(value interface{}) error {
36
40
}
37
41
}
38
42
43
+ // NodePublic is a wrapper around a key.NodePublic which represents the
44
+ // Tailscale disco key for an agent.
39
45
type DiscoPublic key.DiscoPublic
40
46
41
47
func (n DiscoPublic ) String () string {
42
48
return key .DiscoPublic (n ).String ()
43
49
}
44
50
51
+ // This is necessary so DiscoPublic can be serialized in JSON loggers.
45
52
func (n DiscoPublic ) MarshalJSON () ([]byte , error ) {
46
53
j , err := key .DiscoPublic (n ).MarshalText ()
47
54
// surround in quotes to make it a JSON string
48
- j = append ([]byte {'"' }, j ... )
49
- j = append (j , '"' )
55
+ j = append ([]byte {'"' }, append (j , '"' )... )
50
56
return j , err
51
57
}
52
58
59
+ // Value is so DiscoPublic can be inserted into the database.
53
60
func (n DiscoPublic ) Value () (driver.Value , error ) {
54
61
return key .DiscoPublic (n ).MarshalText ()
55
62
}
56
63
64
+ // Scan is so DiscoPublic can be read from the database.
57
65
func (n * DiscoPublic ) Scan (value interface {}) error {
58
66
switch v := value .(type ) {
59
67
case []byte :
0 commit comments