func ParseByRange(rngs string, size int64) ([]ReqRange, error) {
	rngerr := errors.New("bad range")
	var ranges []ReqRange
	const headb = "bytes="
	if !strings.HasPrefix(rngs, headb) {
		return nil, rngerr
	}
	for _, rngobj := range strings.Split(rngs[len(headb):], ",") {
		rngobj = strings.TrimSpace(rngobj)
		if rngobj == "" {
			continue
		}
		i := strings.Index(rngobj, "-")
		if i < 0 {
			return nil, rngerr
		}
		start, end := strings.TrimSpace(rngobj[:i]), strings.TrimSpace(rngobj[i+1:])
		var r ReqRange
		if start == "" {
			i, err := strconv.ParseInt(end, 10, 64)
			if err != nil {
				return nil, rngerr
			}
			if i > size {
				i = size
			}
			r.start = size - i
			r.length = size - r.start
		} else {
			i, err := strconv.ParseInt(start, 10, 64)
			if err != nil || i >= size || i < 0 {
				return nil, rngerr
			}
			r.start = i
			if end == "" {
				r.length = size - r.start
			} else {
				i, err := strconv.ParseInt(end, 10, 64)
				if err != nil || r.start > i {
					return nil, rngerr
				}
				if i >= size {
					i = size - 1
				}
				r.length = i - r.start + 1
			}
		}
		ranges = append(ranges, r)
	}
	return ranges, nil
}
Ranges Helpers
ParseByRange : Accept-Ranges helper
package main
import (
	"errors"
	"strconv"
	"strings"
)