Add the protobuf
package
This commit is contained in:
parent
13282a8731
commit
d1a285fd12
4 changed files with 12 additions and 7 deletions
|
@ -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"
|
|
@ -1,4 +1,4 @@
|
|||
package boltstore;
|
||||
package protobuf;
|
||||
|
||||
message Session {
|
||||
optional bytes Values = 1;
|
10
session.go
10
session.go
|
@ -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}
|
||||
}
|
||||
|
|
3
store.go
3
store.go
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue