Add the protobuf package

This commit is contained in:
yosssi 2014-06-14 03:42:50 +09:00
parent 13282a8731
commit d1a285fd12
4 changed files with 12 additions and 7 deletions

View file

@ -3,7 +3,7 @@
// DO NOT EDIT!
/*
Package boltstore is a generated protocol buffer package.
Package protobuf is a generated protocol buffer package.
It is generated from these files:
session.proto
@ -11,7 +11,7 @@ It is generated from these files:
It has these top-level messages:
Session
*/
package boltstore
package protobuf
import proto "code.google.com/p/gogoprotobuf/proto"
import json "encoding/json"

View file

@ -1,4 +1,4 @@
package boltstore;
package protobuf;
message Session {
optional bytes Values = 1;

View file

@ -1,12 +1,16 @@
package boltstore
import "time"
import (
"time"
"github.com/yosssi/boltstore/protobuf"
)
// NewSession creates and returns a session data.
func NewSession(values []byte, maxAge int) *Session {
func NewSession(values []byte, maxAge int) *protobuf.Session {
var expiresAt int64
if maxAge > 0 {
expiresAt = time.Now().Unix() + int64(maxAge)
}
return &Session{Values: values, ExpiresAt: &expiresAt}
return &protobuf.Session{Values: values, ExpiresAt: &expiresAt}
}

View file

@ -12,6 +12,7 @@ import (
"github.com/boltdb/bolt"
"github.com/gorilla/securecookie"
"github.com/gorilla/sessions"
"github.com/yosssi/boltstore/protobuf"
)
// store represents a session store.
@ -108,7 +109,7 @@ func (s *store) load(session *sessions.Session) (bool, error) {
if data == nil {
return nil
}
sessionData := &Session{}
sessionData := &protobuf.Session{}
// Convert the byte slice to the Session struct value.
if err := proto.Unmarshal(data, sessionData); err != nil {
return err