code: func (d *ADS1x15Driver) BestGainForVoltage(voltage float64) (bestGain int, err error) {
  	var max float64
  	difference := math.MaxFloat64
  	currentBestGain := -1
  
  	for key, value := range d.gainVoltage {
  		max = math.Max(max, value)
  		newDiff := value - voltage
  		if newDiff >= 0 && newDiff < difference {
  			difference = newDiff
  			currentBestGain = key
  		}
  	}
  
  	if currentBestGain < 0 {
  		err = fmt.Errorf("The maximum voltage which can be read is %f", max)
  		return
  	}
  
  	bestGain = currentBestGain
  	return
  }
docs: // BestGainForVoltage returns the gain the most adapted to read up to the specified difference of potential.