sum7
/
yaja
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
yaja/server/utils/main.go

26 lines
526 B
Go
Raw Normal View History

2017-12-16 23:20:46 +01:00
package utils
2017-12-14 21:30:07 +01:00
import (
"crypto/rand"
"encoding/binary"
"fmt"
2017-12-16 23:20:46 +01:00
2018-02-07 15:34:18 +01:00
"dev.sum7.eu/genofire/yaja/model"
2017-12-14 21:30:07 +01:00
)
// Cookie is used to give a unique identifier to each request.
type Cookie uint64
2017-12-16 23:20:46 +01:00
func CreateCookie() Cookie {
2017-12-14 21:30:07 +01:00
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[:]))
}
2017-12-16 23:20:46 +01:00
func CreateCookieString() string {
return fmt.Sprintf("%x", CreateCookie())
2017-12-14 21:30:07 +01:00
}
2017-12-16 23:20:46 +01:00
type DomainRegisterAllowed func(*model.JID) bool