Esempio n. 1
1
// Human-friendly Unique ID based on Sonyflake and Base36.
func HFUID() string {
	flake := sonyflake.NewSonyflake(sonyflake.Settings{})
	newref, _ := flake.NextID()
	buf := make([]byte, 0)
	buf = Base36Encode(buf, big.NewInt(int64(newref)))
	return string(buf)
}
Esempio n. 2
0
func init() {
	var st sonyflake.Settings
	st.MachineID = awsutil.AmazonEC2MachineID
	sf = sonyflake.NewSonyflake(st)
	if sf == nil {
		panic("sonyflake not created")
	}
}
Esempio n. 3
0
func init() {
	var st sonyflake.Settings
	// st.StartTime = time.Now()
	// st.MachineID = awsutil.AmazonEC2MachineID
	st.MachineID = machineid.MachineID
	sf = sonyflake.NewSonyflake(st)
	if sf == nil {
		panic("sonyflake not created")
	}
}
Esempio n. 4
0
func init() {
	var st sonyflake.Settings
	//TODO integrate google's instance id if on GCE...
	// https://github.com/GoogleCloudPlatform/gcloud-golang/blob/master/compute/metadata/metadata.go#L155
	// https://github.com/GoogleCloudPlatform/gcloud-golang/blob/master/compute/metadata/metadata.go#L250
	// if metadata.OnGCE() {
	//     st.MachineID = func(){ return toIn16( metadata.InstanceId() ) }
	// }
	sf = sonyflake.NewSonyflake(st)
	if sf == nil {
		panic("sonyflake not created")
	}
}
Esempio n. 5
0
func generateAnchor() string {
	flake := sonyflake.NewSonyflake(sonyflake.Settings{})
	newref, _ := flake.NextID()
	return fmt.Sprintf("%x", farm.Hash32([]byte(fmt.Sprintf("%d", newref))))
}