The sort package includes binary search for sorted slices:
numbers := []int{1, 3, 5, 7, 9}
i := sort.SearchInts(numbers, 5) // returns 2
SearchInts returns the index where the value is or would be inserted. Verify the value was found:
if i < len(numbers) && numbers[i] == 5 {
fmt.Println("Found at index", i)
}
For unsorted slices, use a simple loop to search.