26 lines
525 B
Go
26 lines
525 B
Go
package utils
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/binary"
|
|
"fmt"
|
|
|
|
"github.com/genofire/yaja/model"
|
|
)
|
|
|
|
// Cookie is used to give a unique identifier to each request.
|
|
type Cookie uint64
|
|
|
|
func CreateCookie() Cookie {
|
|
var buf [8]byte
|
|
if _, err := rand.Reader.Read(buf[:]); err != nil {
|
|
panic("Failed to read random bytes: " + err.Error())
|
|
}
|
|
return Cookie(binary.LittleEndian.Uint64(buf[:]))
|
|
}
|
|
func CreateCookieString() string {
|
|
return fmt.Sprintf("%x", CreateCookie())
|
|
}
|
|
|
|
type DomainRegisterAllowed func(*model.JID) bool
|