2017-07-22 21:22:00 -07:00
|
|
|
package id
|
|
|
|
|
|
|
|
import (
|
2017-08-05 15:02:26 -07:00
|
|
|
"hash/fnv"
|
2017-10-20 19:21:44 -07:00
|
|
|
"time"
|
2017-08-05 15:02:26 -07:00
|
|
|
|
2017-08-19 16:58:23 -07:00
|
|
|
"github.com/mxpv/podsync/pkg/api"
|
2017-10-20 19:21:44 -07:00
|
|
|
"github.com/ventu-io/go-shortid"
|
2017-07-22 21:22:00 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type hashId struct {
|
2017-10-20 19:21:44 -07:00
|
|
|
sid *shortid.Shortid
|
2017-07-22 21:22:00 -07:00
|
|
|
}
|
|
|
|
|
2017-08-05 15:02:26 -07:00
|
|
|
func hashString(s string) int {
|
|
|
|
h := fnv.New32a()
|
|
|
|
h.Write([]byte(s))
|
|
|
|
return int(h.Sum32())
|
|
|
|
}
|
|
|
|
|
2017-08-13 14:50:59 -07:00
|
|
|
func (h *hashId) Generate(feed *api.Feed) (string, error) {
|
2017-10-20 19:21:44 -07:00
|
|
|
return h.sid.Generate()
|
2017-07-22 21:22:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewIdGenerator() (*hashId, error) {
|
2017-10-20 19:21:44 -07:00
|
|
|
sid, err := shortid.New(1, shortid.DefaultABC, uint64(time.Now().UnixNano()))
|
2017-08-13 19:28:43 -07:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-10-20 19:21:44 -07:00
|
|
|
|
|
|
|
return &hashId{sid}, nil
|
2017-07-22 21:22:00 -07:00
|
|
|
}
|