Created
December 24, 2021 02:58
-
-
Save laixintao/a6c7f3f47eb06a81dcb57a780b6ccad0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
) | |
func main() { | |
fmt.Printf("Generated service id: %s\n", CreateServiceID()) | |
} | |
func CastUint64ToString(id uint64) (serviceID string) { | |
return fmt.Sprintf("%017x", id) | |
} | |
func CreateServiceID() string { | |
randnum := rand.Uint64() << 28 | |
fmt.Println(randnum) | |
timestamp := uint64(time.Now().Unix()) & 0xfffffff | |
fmt.Println(timestamp) | |
num := (randnum) | (timestamp) | |
fmt.Println(num) | |
str := CastUint64ToString(num) | |
fmt.Println(str) | |
return str | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment