Example #1
0
func FindSession(ctx *context.Context, id []byte) (*Session, error) {
	ro := rocksdb.NewReadOptions()
	defer ro.Close()

	buf, err := ctx.Db.Get(ro, id)
	if err != nil {
		return nil, err
	}

	if buf == nil {
		return nil, ErrNotFound
	}

	s := &Session{}
	if err := s.Decode(bytes.NewBuffer(buf)); err != nil {
		return nil, err
	}

	return s, nil
}
Example #2
0
func FindUser(ctx *context.Context, id uint64) (*User, error) {
	ro := rocksdb.NewReadOptions()
	defer ro.Close()

	buf, err := ctx.Db.Get(ro, userKeyBytes(id))
	if err != nil {
		return nil, err
	}

	if buf == nil {
		return nil, ErrNotFound
	}

	u := &User{}
	if err := u.Decode(bytes.NewBuffer(buf)); err != nil {
		return nil, err
	}

	return u, nil
}