zguid.go 389 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
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)))

Vladimir Barsukov's avatar
fix    
Vladimir Barsukov committed
16
	return fmt.Sprintf("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", 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])
Vladimir Barsukov's avatar
zguid  
Vladimir Barsukov committed
17
}