user/file.go
func lookUp(_row row, _field field, value interface{}, n int) (interface{}, error) {
	if n == 0 {
		return nil, errSearch
	}

	dbf, err := openDBFile(_row.filename(), os.O_RDONLY)
	if err != nil {
		return nil, err
	}
	defer dbf.close()

	// Lines where a field is matched.
	entries := make([]interface{}, 0, 0)

	for {
		line, _, err := dbf.rd.ReadLine()
		if err == io.EOF {
			break
		}

		entry := _row.lookUp(string(line), _field, value)
		if entry != nil {
			entries = append(entries, entry)
		}

		if n < 0 {
			continue
		} else if n == len(entries) {
			break
		}
	}

	if len(entries) != 0 {
		return entries, nil
	}
	return nil, NoFoundError{_row.filename(), _field.String(), value}
}
func lookUp(_row row, _field field, value interface{}, n int) (interface{}, error) {
	if n == 0 {
		return nil, errSearch
	}

	dbf, err := openDBFile(_row.filename(), os.O_RDONLY)
	if err != nil {
		return nil, err
	}
	defer dbf.close()

	// Lines where a field is matched.
	entries := make([]interface{}, 0, 0)

	for {
		line, _, err := dbf.rd.ReadLine()
		if err == io.EOF {
			break
		}

		entry := _row.lookUp(string(line), _field, value)
		if entry != nil {
			entries = append(entries, entry)
		}

		if n < 0 {
			continue
		} else if n == len(entries) {
			break
		}
	}

	if len(entries) != 0 {
		return entries, nil
	}
	return nil, NoFoundError{_row.filename(), _field.String(), value}
}
func lookUp ( _row row , _field field , value interface { } , n int ) ( interface { } , error ) { if n == 0 { return nil , errSearch } dbf , err := openDBFile ( _row . filename ( ) , os . O_RDONLY ) if err != nil { return nil , err } defer dbf . close ( ) // Lines where a field is matched. entries := make ( [ ] interface { } , 0 , 0 ) for { line , _ , err := dbf . rd . ReadLine ( ) if err == io . EOF { break } entry := _row . lookUp ( string ( line ) , _field , value ) if entry != nil { entries = append ( entries , entry ) } if n < 0 { continue } else if n == len ( entries ) { break } } if len ( entries ) != 0 { return entries , nil } return nil , NoFoundError { _row . filename ( ) , _field . String ( ) , value } }
// lookUp is a generic parser to looking for a value.
//
// The count determines the number of fields to return:
//   n > 0: at most n fields
//   n == 0: the result is nil (zero fields)
//   n < 0: all fields
lookUp is a generic parser to looking for a value . The count determines the number of fields to return : n > 0 : at most n fields n == 0 : the result is nil ( zero fields ) n < 0 : all fields