You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: session_iterate.go
    path of file: ./repos/faygo/vendor/xorm.io/xorm
    
    the code of the file until where you have to start completion: // Copyright 2016 The Xorm Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package xorm

import "reflect"

// IterFunc only use by Iterate
type IterFunc func(idx int, bean interface{}) error

// Rows return sql.Rows compatible Rows obj, as a forward Iterator object for iterating record by record, bean's non-empty fields
// are conditions.
func (session *Session) Rows(bean interface{}) (*Rows, error) {
	return newRows(session, bean)
}

// Iterate record by record handle records from table, 
    
func (session *Session) bufferIterate(bean interface{}, fun IterFunc) error {
	if session.isAutoClose {
		defer session.Close()
	}

	var bufferSize = session.statement.bufferSize
	var limit = session.statement.LimitN
	if limit > 0 && bufferSize > limit {
		bufferSize = limit
	}
	var start = session.statement.Start
	v := rValue(bean)
	sliceType := reflect.SliceOf(v.Type())
	var idx = 0
	for {
		slice := reflect.New(sliceType)
		if err := session.Limit(bufferSize, start).find(slice.Interface(), bean); err != nil {
			return err
		}

		for i := 0; i < slice.Elem().Len(); i++ {
			if err := fun(idx, slice.Elem().Index(i).Addr().Interface()); err != nil {
				return err
			}
			idx++
		}

		start = start + slice.Elem().Len()
		if limit > 0 && idx+bufferSize > limit {
			bufferSize = limit - idx
		}

		if bufferSize <= 0 || slice.Elem().Len() < bufferSize || idx == limit {
			break
		}
	}

	return nil
}