This commit is contained in:
yanweidong 2024-09-20 14:45:34 +08:00
parent 0be9490840
commit 8537320513
2 changed files with 1 additions and 23 deletions

View File

@ -1,31 +1,9 @@
package utils package utils
import ( import (
"strconv"
"github.com/google/uuid"
"github.com/jaevor/go-nanoid"
ulid "github.com/oklog/ulid/v2" ulid "github.com/oklog/ulid/v2"
) )
func NanoID() string {
nanoid, _ := nanoid.CustomASCII("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 21)
return nanoid()
}
func NanoIDInt() (id int64, err error) {
decenaryID, err := nanoid.CustomASCII("0123456789", 18)
if err != nil {
return
}
id, err = strconv.ParseInt(decenaryID(), 10, 64)
return
}
func UUID() string {
return uuid.NewString()
}
func ULID() string { func ULID() string {
return ulid.Make().String() return ulid.Make().String()
} }

View File

@ -99,7 +99,7 @@ func HttpPost(url string, header map[string]string, data []byte) ([]byte, error)
} }
request.Header.Set("Content-Type", "application/json;charset=UTF-8") request.Header.Set("Content-Type", "application/json;charset=UTF-8")
request.Header.Set("Request-Id", NanoID()) request.Header.Set("Request-Id", ULID())
for key, val := range header { for key, val := range header {
request.Header.Set(key, val) request.Header.Set(key, val)