func setUserId() { userName := beego.AppConfig.String("user") u, err := user.Lookup(userName) if err != nil { fmt.Println("user config:", err) return } gid, _ := strconv.ParseInt(u.Gid, 0, 0) uid, _ := strconv.ParseInt(u.Uid, 0, 0) if err := syscall.Setregid(int(gid), int(gid)); err != nil { fmt.Println("setregid:", err) } if err := syscall.Setreuid(int(uid), int(uid)); err != nil { fmt.Println("setreuid:", err) } }
// darwin doesn't seem to have saved GIDs, so use setregid func setresgid(rgid, egid, sgid int) error { return syscall.Setregid(rgid, egid) }
func setAllGid(gid int) error { return syscall.Setregid(gid, gid) }