id.go 380 B

123456789101112131415161718192021
  1. package clinit
  2. import (
  3. "github.com/sony/sonyflake"
  4. "github.com/sony/sonyflake/awsutil"
  5. )
  6. var traceSF *sonyflake.Sonyflake
  7. func InitUniqueID() {
  8. var st sonyflake.Settings
  9. st.MachineID = awsutil.AmazonEC2MachineID
  10. traceSF = sonyflake.NewSonyflake(st)
  11. if traceSF == nil {
  12. panic("init unique id panic")
  13. }
  14. }
  15. func GetTraceID() (uint64, error) {
  16. return traceSF.NextID()
  17. }