mirror of
https://github.com/mxpv/podsync.git
synced 2024-05-11 05:55:04 +00:00
33 lines
532 B
Go
33 lines
532 B
Go
package id
|
|
|
|
import (
|
|
"hash/fnv"
|
|
"time"
|
|
|
|
"github.com/mxpv/podsync/pkg/api"
|
|
"github.com/ventu-io/go-shortid"
|
|
)
|
|
|
|
type hashId struct {
|
|
sid *shortid.Shortid
|
|
}
|
|
|
|
func hashString(s string) int {
|
|
h := fnv.New32a()
|
|
h.Write([]byte(s))
|
|
return int(h.Sum32())
|
|
}
|
|
|
|
func (h *hashId) Generate(feed *api.Feed) (string, error) {
|
|
return h.sid.Generate()
|
|
}
|
|
|
|
func NewIdGenerator() (*hashId, error) {
|
|
sid, err := shortid.New(1, shortid.DefaultABC, uint64(time.Now().UnixNano()))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &hashId{sid}, nil
|
|
}
|