func (bs *badgerStorage) loadHardState(txn *badger.Txn) (*raftpb.HardState, error) {
	hs := &raftpb.HardState{}
	var item *badger.Item
	var txnErr error
	var bites []byte
	item, txnErr = txn.Get(hardStateKey)
	if txnErr == badger.ErrKeyNotFound {
		return hs, nil
	} else if txnErr != nil {
		return hs, txnErr
	}

	bites, txnErr = item.Value()
	if txnErr != nil {
		return hs, txnErr
	}

	txnErr = hs.Unmarshal(bites)
	if txnErr != nil {
		return hs, txnErr
	}

	return hs, nil
}
// NB: can't return nil and must handle "key not found" errors
can't return nil and must handle "key not found" errors
// NB : can ' t return nil and must handle " key not found " errors
func (bs *badgerStorage) loadHardState(txn *badger.Txn) (*raftpb.HardState, error) {
	hs := &raftpb.HardState{}
	var item *badger.Item
	var txnErr error
	var bites []byte
	item, txnErr = txn.Get(hardStateKey)
	if txnErr == badger.ErrKeyNotFound {
		return hs, nil
	} else if txnErr != nil {
		return hs, txnErr
	}
	bites, txnErr = item.Value()
	if txnErr != nil {
		return hs, txnErr
	}
	txnErr = hs.Unmarshal(bites)
	if txnErr != nil {
		return hs, txnErr
	}
	return hs, nil
}
func ( bs * badgerStorage ) loadHardState ( txn * badger . Txn ) ( * raftpb . HardState , error ) { hs := & raftpb . HardState { } var item * badger . Item var txnErr error var bites [ ] byte item , txnErr = txn . Get ( hardStateKey ) if txnErr == badger . ErrKeyNotFound { return hs , nil } else if txnErr != nil { return hs , txnErr } bites , txnErr = item . Value ( ) if txnErr != nil { return hs , txnErr } txnErr = hs . Unmarshal ( bites ) if txnErr != nil { return hs , txnErr } return hs , nil }
can't return nil and must handle "key not found" errors
can ' t return nil and must handle " key not found " errors