user/user.go
func (*User) lookUp(line string, f field, value interface{}) interface{} {
	_field := f.(userField)
	allField := strings.Split(line, ":")
	intField := make(map[int]int)

	// Check integers
	var err error
	if intField[2], err = strconv.Atoi(allField[2]); err != nil {
		panic(atoiError{_USER_FILE, line, "UID"})
	}
	if intField[3], err = strconv.Atoi(allField[3]); err != nil {
		panic(atoiError{_USER_FILE, line, "GID"})
	}

	// Check fields
	var isField bool
	if U_NAME&_field != 0 && allField[0] == value.(string) {
		isField = true
	} else if U_PASSWD&_field != 0 && allField[1] == value.(string) {
		isField = true
	} else if U_UID&_field != 0 && intField[2] == value.(int) {
		isField = true
	} else if U_GID&_field != 0 && intField[3] == value.(int) {
		isField = true
	} else if U_GECOS&_field != 0 && allField[4] == value.(string) {
		isField = true
	} else if U_DIR&_field != 0 && allField[5] == value.(string) {
		isField = true
	} else if U_SHELL&_field != 0 && allField[6] == value.(string) {
		isField = true
	} else if U_ALL&_field != 0 {
		isField = true
	}

	if isField {
		return &User{
			Name:     allField[0],
			password: allField[1],
			UID:      intField[2],
			GID:      intField[3],
			Gecos:    allField[4],
			Dir:      allField[5],
			Shell:    allField[6],
		}
	}
	return nil
}
func (*User) lookUp(line string, f field, value interface{}) interface{} {
	_field := f.(userField)
	allField := strings.Split(line, ":")
	intField := make(map[int]int)

	// Check integers
	var err error
	if intField[2], err = strconv.Atoi(allField[2]); err != nil {
		panic(atoiError{_USER_FILE, line, "UID"})
	}
	if intField[3], err = strconv.Atoi(allField[3]); err != nil {
		panic(atoiError{_USER_FILE, line, "GID"})
	}

	// Check fields
	var isField bool
	if U_NAME&_field != 0 && allField[0] == value.(string) {
		isField = true
	} else if U_PASSWD&_field != 0 && allField[1] == value.(string) {
		isField = true
	} else if U_UID&_field != 0 && intField[2] == value.(int) {
		isField = true
	} else if U_GID&_field != 0 && intField[3] == value.(int) {
		isField = true
	} else if U_GECOS&_field != 0 && allField[4] == value.(string) {
		isField = true
	} else if U_DIR&_field != 0 && allField[5] == value.(string) {
		isField = true
	} else if U_SHELL&_field != 0 && allField[6] == value.(string) {
		isField = true
	} else if U_ALL&_field != 0 {
		isField = true
	}

	if isField {
		return &User{
			Name:     allField[0],
			password: allField[1],
			UID:      intField[2],
			GID:      intField[3],
			Gecos:    allField[4],
			Dir:      allField[5],
			Shell:    allField[6],
		}
	}
	return nil
}
func ( * User ) lookUp ( line string , f field , value interface { } ) interface { } { _field := f . ( userField ) allField := strings . Split ( line , " " ) intField := make ( map [ int ] int ) // Check integers var err error if intField [ 2 ] , err = strconv . Atoi ( allField [ 2 ] ) ; err != nil { panic ( atoiError { _USER_FILE , line , " " } ) } if intField [ 3 ] , err = strconv . Atoi ( allField [ 3 ] ) ; err != nil { panic ( atoiError { _USER_FILE , line , " " } ) } // Check fields var isField bool if U_NAME & _field != 0 && allField [ 0 ] == value . ( string ) { isField = true } else if U_PASSWD & _field != 0 && allField [ 1 ] == value . ( string ) { isField = true } else if U_UID & _field != 0 && intField [ 2 ] == value . ( int ) { isField = true } else if U_GID & _field != 0 && intField [ 3 ] == value . ( int ) { isField = true } else if U_GECOS & _field != 0 && allField [ 4 ] == value . ( string ) { isField = true } else if U_DIR & _field != 0 && allField [ 5 ] == value . ( string ) { isField = true } else if U_SHELL & _field != 0 && allField [ 6 ] == value . ( string ) { isField = true } else if U_ALL & _field != 0 { isField = true } if isField { return & User { Name : allField [ 0 ] , password : allField [ 1 ] , UID : intField [ 2 ] , GID : intField [ 3 ] , Gecos : allField [ 4 ] , Dir : allField [ 5 ] , Shell : allField [ 6 ] , } } return nil }
// == Lookup
//
// lookUp parses the user line searching a value into the field.
// Returns nil if is not found.
== Lookup lookUp parses the user line searching a value into the field . Returns nil if is not found .