switch url to id in invitation process
This commit is contained in:
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func (r *RedisRouter) CreateInvitation(invitation []byte, timeout int, password string, serverTimeout int, urlLen int) (string, time.Time) {
|
||||
id := r.createShortUrl(urlLen)
|
||||
id := r.createShortId(urlLen)
|
||||
if timeout > serverTimeout {
|
||||
timeout = serverTimeout
|
||||
}
|
||||
@ -54,17 +54,17 @@ func (r *RedisRouter) GetInvitationAnswer(id string) ([]byte, error) {
|
||||
return []byte(mwan), nil
|
||||
}
|
||||
|
||||
func (r *RedisRouter) createShortUrl(length int) string {
|
||||
url := ""
|
||||
func (r *RedisRouter) createShortId(length int) string {
|
||||
id := ""
|
||||
alphabet := "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
|
||||
// for not in redis
|
||||
for {
|
||||
for i := 1; i <= length; i++ {
|
||||
url += string(alphabet[rand.Intn(61)])
|
||||
id += string(alphabet[rand.Intn(61)])
|
||||
}
|
||||
if r.Client.Get("mwiv:"+url).Err() == redis.Nil {
|
||||
if r.Client.Get("mwiv:"+id).Err() == redis.Nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
return url
|
||||
return id
|
||||
}
|
||||
|
Reference in New Issue
Block a user