Initial commit
This commit is contained in:
27
server/framework/utils/hashids.go
Normal file
27
server/framework/utils/hashids.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package Utils
|
||||
|
||||
import (
|
||||
"Game/framework/config"
|
||||
"github.com/speps/go-hashids"
|
||||
)
|
||||
|
||||
func EncodeId(len int, id ...int) string {
|
||||
hd := hashids.NewData()
|
||||
hd.Salt = Config.Get.Hash.Salt
|
||||
hd.MinLength = len
|
||||
h := hashids.NewWithData(hd)
|
||||
e, _ := h.Encode(id)
|
||||
return e
|
||||
}
|
||||
|
||||
func DecodeId(len int, encodedId string) ([]int, error) {
|
||||
hd := hashids.NewData()
|
||||
hd.Salt = Config.Get.Hash.Salt
|
||||
hd.MinLength = len
|
||||
h := hashids.NewWithData(hd)
|
||||
d, err := h.DecodeWithError(encodedId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
Reference in New Issue
Block a user