Exemplo n.º 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
}
Exemplo n.º 2
0
func (c *boltStore) Close() error {
	// Invoke a reaper which checks and removes expired sessions periodically.
	if c.quiteC != nil && c.doneC != nil {
		reaper.Quit(c.quiteC, c.doneC)
	}

	if c.Storex.db != nil {
		c.Storex.db.Close()
	}

	return nil
}