Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

36 lines (27 sloc) 0.752 kb
package socketio
import (
"io"
"crypto/rand"
"os"
)
// SessionID is just a string for now.
type SessionID string
const (
// Length of the session ids.
SessionIDLength = 16
// Charset from which to build the session ids.
SessionIDCharset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
)
// NewSessionID creates a new ~random session id that is SessionIDLength long and
// consists of random characters from the SessionIDCharset.
func NewSessionID() (sid SessionID, err os.Error) {
b := make([]byte, SessionIDLength)
if _, err = io.ReadFull(rand.Reader, b); err != nil {
return
}
for i := 0; i < SessionIDLength; i++ {
b[i] = SessionIDCharset[b[i]%uint8(len(SessionIDCharset))]
}
sid = SessionID(b)
return
}
Jump to Line
Something went wrong with that request. Please try again.