zguid.go 357 Bytes
Newer Older
Vladimir Barsukov's avatar
zguid  
Vladimir Barsukov committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package zguid

import (
	"crypto/md5"
	"fmt"
	"github.com/google/uuid"
)

func New() string {
	return uuid.NewString()
}

func Hash(a any) string {
	b := md5.Sum([]byte(fmt.Sprintf("%v", a)))

	return fmt.Sprintf("%x%x%x%x-%x%x-%x%x-%x%x-%x%x%x%x%x%x", b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15])
}