// Copyright (C) 2018 Marius Schellenberger

// +build go1.11

package godrop

import (
	"os/user"
	"strconv"
)

func atoi(a string) (int, error) {
	i, err := strconv.Atoi(a)
	if err != nil {
		return -1, err
	}
	return i, nil
}

func userID(username string) (int, error) {
	u, err := user.Lookup(username)
	if err != nil {
		return -1, err
	}
	return atoi(u.Uid)
}

func groupID(name string) (int, error) {
	g, err := user.LookupGroup(name)
	if err != nil {
		return -1, err
	}
	return atoi(g.Gid)
}
