func GetMemoryInfo() (total, available int) {
	file, err := os.Open("/proc/meminfo")
	if err != nil {
		return -1, -1
	}
	total, available = getMemoryInfo(file)
	_ = file.Close()
	return
}
GetMemoryInfo returns the both the total amount of memory installed in the
device and the amount of memory currently available, in MiB.  A return value
of -1 indicates that an error occurred computing the return value.
package deviceinfo
import (
	"bufio"
	"io"
	"os"
	"regexp"
	"strconv"
	"syscall"
)
var memTotalRegexp *regexp.Regexp
var memFreeRegexp *regexp.Regexp
var memActiveFileRegexp *regexp.Regexp
var memInactiveFileRegexp *regexp.Regexp
var cpuStatsRegexp *regexp.Regexp
func init() {
	memTotalRegexp = regexp.MustCompile(`MemTotal:\s+(\d+)`)
	memFreeRegexp = regexp.MustCompile(`MemFree:\s+(\d+)`)
	memActiveFileRegexp = regexp.MustCompile(`Active\(file\):\s+(\d+)`)
	memInactiveFileRegexp = regexp.MustCompile(`Inactive\(file\):\s+(\d+)`)
	cpuStatsRegexp = regexp.MustCompile(`^cpu[0-9]+.*$`)
}
func grabInt(re *regexp.Regexp, line string, val *int) bool {
	matches := re.FindStringSubmatch(line)
	if matches != nil {
		parsedNum, err := strconv.Atoi(matches[1])
		if err == nil {
			*val = parsedNum
			return true
		}
	}
	return false
}
func getMemoryInfo(file io.Reader) (total, available int) {
	total = -1
	available = -1
	free := -1
	active := -1
	inactive := -1
	scanner := bufio.NewScanner(file)
	for scanner.Scan() && (total == -1 || free == -1 || active == -1 ||
		inactive == -1) {
		line := scanner.Text()
		for _, i := range []struct {
			v *int
			r *regexp.Regexp
		}{
			{&free, memFreeRegexp},
			{&total, memTotalRegexp},
			{&active, memActiveFileRegexp},
			{&inactive, memInactiveFileRegexp},
		} {
			if *i.v == -1 {
				if grabInt(i.r, line, i.v) {
					break
				}
			}
		}
	}
	if free != -1 && active != -1 && inactive != -1 {
		available = (free + active + inactive) / 1024
	}
	if total != -1 {
		total = total / 1024
	}
	return
}