Example #1
0
//./sessions.db
func NewBoltStore(dbFile string, options I.Options, bucketName []byte, keyPairs ...[]byte) (BoltStore, error) {
	var err error
	if boltDB == nil {
		boltDB, err = bolt.Open(dbFile, 0666, nil)
		if err != nil {
			panic(err)
		}
		quiteC, doneC := reaper.Run(boltDB, reaper.Options{})
		onCloseBolt = func() error {
			// Invoke a reaper which checks and removes expired sessions periodically.
			reaper.Quit(quiteC, doneC)
			return nil
		}
		events.AddEvent(`webx.serverExit`, func(_ interface{}, next func(bool)) {
			CloseBolt()
			next(true)
		})
	}
	stor, err := store.New(boltDB, store.Config{
		SessionOptions: sessions.Options{
			Path:     options.Path,
			Domain:   options.Domain,
			MaxAge:   options.MaxAge,
			Secure:   options.Secure,
			HttpOnly: options.HttpOnly,
		},
		DBOptions: store.Options{bucketName},
	}, keyPairs...)
	if err != nil {
		return nil, err
	}
	return &boltStore{stor}, nil
}
Example #2
0
func (c *boltStore) Options(options echo.SessionOptions) {
	c.config.SessionOptions = sessions.Options{
		Path:     options.Path,
		Domain:   options.Domain,
		MaxAge:   options.MaxAge,
		Secure:   options.Secure,
		HttpOnly: options.HttpOnly,
	}
	stor, err := store.New(c.Storex.db, *c.config, c.keyPairs...)
	if err != nil {
		panic(err.Error())
	}
	c.Store = stor
}
Example #3
0
func (b *boltStore) Init() error {
	if b.Storex.db == nil {
		var err error
		b.Storex.db, err = bolt.Open(b.dbFile, 0666, nil)
		if err != nil {
			return err
		}
		b.Storex.Store, err = store.New(b.Storex.db, *b.config, b.keyPairs...)
		if err != nil {
			return err
		}
		b.quiteC, b.doneC = reaper.Run(b.Storex.db, reaper.Options{
			BucketName:    b.config.DBOptions.BucketName,
			CheckInterval: time.Duration(int64(b.config.SessionOptions.MaxAge)) * time.Second,
		})
		runtime.SetFinalizer(b, func(b *boltStore) {
			b.Close()
		})
	}
	b.Storex.initialized = true
	return nil
}