func (r *Range) CheckInt(val int) bool {
	return r.Check(float64(val))
}
CheckInt is a convenience method which does an unchecked type
conversion from an int to a float64.
package nagiosplugin
import (
	"errors"
	"fmt"
	"math"
	"strconv"
	"strings"
)
type Range struct {
	Start         float64
	End           float64
	AlertOnInside bool
}
func ParseRange(rangeStr string) (*Range, error) {
	t := &Range{
		Start:         0,
		End:           math.Inf(1),
		AlertOnInside: false,
	}
	rangeStr = strings.Trim(rangeStr, " \n\r")
	if rangeStr[0] == '@' {
		t.AlertOnInside = true
		rangeStr = rangeStr[1:]
	}
	endPos := strings.Index(rangeStr, ":")
	if endPos > -1 {
		if rangeStr[0] == '~' {
			t.Start = math.Inf(-1)
		} else {
			min, err := strconv.ParseFloat(rangeStr[0:endPos], 64)
			if err != nil {
				return nil, fmt.Errorf("failed to parse lower limit: %v", err)
			}
			t.Start = min
		}
		rangeStr = rangeStr[endPos+1:]
	}
	if len(rangeStr) > 0 {
		max, err := strconv.ParseFloat(rangeStr, 64)
		if err != nil {
			return nil, fmt.Errorf("failed to parse upper limit: %v", err)
		}
		t.End = max
	}
	if t.End < t.Start {
		return nil, errors.New("Invalid range definition. min <= max violated!")
	}
	return t, nil
}
func (r *Range) Check(value float64) bool {
	if r.Start <= value && value <= r.End {
		return r.AlertOnInside
	}
	return !r.AlertOnInside
}