compile-time check for json.Marshaler and json.Unmarshaler.
This commit is contained in:
6
keys.go
6
keys.go
@@ -3,6 +3,7 @@ package nostr
|
|||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
stdjson "encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -65,6 +66,11 @@ var ZeroPK = PubKey{}
|
|||||||
|
|
||||||
type PubKey [32]byte
|
type PubKey [32]byte
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ stdjson.Marshaler = PubKey{}
|
||||||
|
_ stdjson.Unmarshaler = (*PubKey)(nil)
|
||||||
|
)
|
||||||
|
|
||||||
func (pk PubKey) String() string { return "pk::" + pk.Hex() }
|
func (pk PubKey) String() string { return "pk::" + pk.Hex() }
|
||||||
func (pk PubKey) Hex() string { return hex.EncodeToString(pk[:]) }
|
func (pk PubKey) Hex() string { return hex.EncodeToString(pk[:]) }
|
||||||
func (pk PubKey) MarshalJSON() ([]byte, error) {
|
func (pk PubKey) MarshalJSON() ([]byte, error) {
|
||||||
|
|||||||
6
types.go
6
types.go
@@ -2,6 +2,7 @@ package nostr
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
stdjson "encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
@@ -17,6 +18,11 @@ var ZeroID = ID{}
|
|||||||
// ID represents an event id
|
// ID represents an event id
|
||||||
type ID [32]byte
|
type ID [32]byte
|
||||||
|
|
||||||
|
var (
|
||||||
|
_ stdjson.Marshaler = ID{}
|
||||||
|
_ stdjson.Unmarshaler = (*ID)(nil)
|
||||||
|
)
|
||||||
|
|
||||||
func (id ID) String() string { return "id::" + id.Hex() }
|
func (id ID) String() string { return "id::" + id.Hex() }
|
||||||
func (id ID) Hex() string { return hex.EncodeToString(id[:]) }
|
func (id ID) Hex() string { return hex.EncodeToString(id[:]) }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user