码迷,mamicode.com
首页 > 编程语言 > 详细

go语言中os/user包的学习与使用

时间:2017-07-10 14:22:20      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:pre   http   ini   ack   pac   min   home   images   学习   

package main;

import (
	"os/user"
	"fmt"
)

func main() {
	//返回当前用户的结构
	u, _ := user.Current();
	fmt.Println(u.Name);
	//用户主目录
	fmt.Println(u.HomeDir);
	//用户名
	fmt.Println(u.Username);
	//组ID
	fmt.Println(u.Gid);
	//用户ID
	fmt.Println(u.Uid);

	//根据用户名查找用户信息
	u2, _ := user.Lookup("Administrator");
	fmt.Println(u2);

	//根据用户ID查找用户信息
	u3, _ := user.LookupId("S-1-5-21-993545426-2765884555-2597373785-500");
	fmt.Println(u3);
}

技术分享

go语言中os/user包的学习与使用

标签:pre   http   ini   ack   pac   min   home   images   学习   

原文地址:http://www.cnblogs.com/jkko123/p/7145404.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!