2016-07-31 23:56:28 +00:00
|
|
|
package particle
|
|
|
|
|
|
|
|
import (
|
2016-08-01 00:30:34 +00:00
|
|
|
"fmt"
|
|
|
|
"math/rand"
|
|
|
|
"net/url"
|
|
|
|
"time"
|
2016-07-31 23:56:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const hexBytes = "0123456789abcdef"
|
|
|
|
|
|
|
|
func init() {
|
2016-08-01 00:30:34 +00:00
|
|
|
rand.Seed(time.Now().UnixNano())
|
2016-07-31 23:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func RandStringBytes(n int) string {
|
2016-08-01 00:30:34 +00:00
|
|
|
b := make([]byte, n)
|
|
|
|
for i := range b {
|
|
|
|
b[i] = hexBytes[rand.Intn(len(hexBytes))]
|
|
|
|
}
|
|
|
|
return string(b)
|
2016-07-31 23:56:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewEventURLEncoded() string {
|
2016-08-01 00:30:34 +00:00
|
|
|
rand.Seed(time.Now().UnixNano())
|
|
|
|
return fmt.Sprintf("event=%v&data=%v&published_at=%v&coreid=%v",
|
|
|
|
"event",
|
|
|
|
rand.Intn(1000),
|
|
|
|
url.QueryEscape(time.Now().Format(time.RFC3339)),
|
|
|
|
RandStringBytes(24))
|
|
|
|
}
|