signald-go/signald/utils.go

30 lines
550 B
Go
Raw Normal View History

2021-01-31 05:36:35 +00:00
package signald
import (
"math/rand"
2021-02-02 01:37:48 +00:00
"gitlab.com/signald/signald-go/signald/client-protocol/v0"
2021-01-31 05:36:35 +00:00
)
const idsize = 10
var charset = []rune("abcdefghijklmnopqrstuvwxyz0123456789")
2021-01-31 12:59:36 +00:00
// GenerateID is a helper function to generate random request IDs.
2021-01-31 05:36:35 +00:00
func GenerateID() string {
id := make([]rune, idsize)
for i := range id {
id[i] = charset[rand.Intn(len(charset))]
}
return string(id)
}
2021-02-02 01:37:48 +00:00
func GetLegacyResponse(c chan v0.LegacyResponse, id string) v0.LegacyResponse {
for {
message := <-c
if message.ID == id {
return message
}
}
}