boltstore/shared/utils.go

27 lines
733 B
Go
Raw Normal View History

2014-06-14 20:15:10 +04:00
package shared
import (
"time"
"code.google.com/p/gogoprotobuf/proto"
"github.com/yosssi/boltstore/shared/protobuf"
)
// Session converts the byte slice to the session struct value.
func Session(data []byte) (protobuf.Session, error) {
session := protobuf.Session{}
err := proto.Unmarshal(data, &session)
return session, err
}
// Expired checks if the session is expired.
func Expired(session protobuf.Session) bool {
return *session.ExpiresAt > 0 && *session.ExpiresAt <= time.Now().Unix()
}
2014-06-17 12:53:24 +04:00
// NewSession creates and returns a session data.
func NewSession(values []byte, maxAge int) *protobuf.Session {
expiresAt := time.Now().Unix() + int64(maxAge)
return &protobuf.Session{Values: values, ExpiresAt: &expiresAt}
}