1 Star 0 Fork 0

zhangjungang/beats

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
user_cache.go 697 Bytes
一键复制 编辑 原始数据 按行查看 历史
Andrew Kroh 提交于 2016-12-22 18:51 . Add system socket MetricSet
package socket
import (
"os/user"
"strconv"
)
// UserCache is a cache of UID to username.
type UserCache map[int]string
// NewUserCache returns a new UserCache.
func NewUserCache() UserCache {
return map[int]string{0: "root"}
}
// LookupUID looks up a UID and returns the username associated with it. If
// no username could be found an empty string is returned. The value will be
// cached forever.
func (c UserCache) LookupUID(uid int) string {
if username, found := c[uid]; found {
return username
}
// Cache the value (even on error).
username, err := user.LookupId(strconv.Itoa(uid))
if err != nil {
c[uid] = ""
return ""
}
c[uid] = username.Name
return username.Name
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhangjungang/beats.git
git@gitee.com:zhangjungang/beats.git
zhangjungang
beats
beats
v6.1.0

搜索帮助