This commit is contained in:
36
toot/toot.go
36
toot/toot.go
@@ -1,27 +1,30 @@
|
||||
package toot
|
||||
|
||||
import "fmt"
|
||||
import "encoding/json"
|
||||
import "errors"
|
||||
import "strings"
|
||||
import "git.eeqj.de/sneak/feta/jsonapis"
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
//import "github.com/davecgh/go-spew/spew"
|
||||
import "github.com/rs/zerolog/log"
|
||||
"git.eeqj.de/sneak/feta/jsonapis"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
//import "encoding/hex"
|
||||
import mh "github.com/multiformats/go-multihash"
|
||||
import mhopts "github.com/multiformats/go-multihash/opts"
|
||||
//import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
//import "encoding/hex"
|
||||
mh "github.com/multiformats/go-multihash"
|
||||
|
||||
mhopts "github.com/multiformats/go-multihash/opts"
|
||||
)
|
||||
|
||||
// Hash is a type for storing a string-based base58 multihash of a
|
||||
// toot's identity
|
||||
type Hash string
|
||||
|
||||
// Toot is an object we use internally for storing a discovered toot
|
||||
type Toot struct {
|
||||
Original []byte
|
||||
Parsed *jsonapis.APISerializedToot
|
||||
Hash Hash
|
||||
Hash string
|
||||
FromHost string
|
||||
}
|
||||
|
||||
@@ -111,7 +114,14 @@ func (t *Toot) identityHashInput() string {
|
||||
)
|
||||
}
|
||||
|
||||
func (t *Toot) GetHash() string {
|
||||
if t.Hash == "" {
|
||||
t.calcHash()
|
||||
}
|
||||
return t.Hash
|
||||
}
|
||||
|
||||
func (t *Toot) calcHash() {
|
||||
hi := t.identityHashInput()
|
||||
t.Hash = Hash(t.multiHash([]byte(hi)))
|
||||
t.Hash = string(t.multiHash([]byte(hi)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user