Golang operating system

From wikinotes
Revision as of 13:13, 18 June 2022 by Will (talk | contribs) (Created page with " = Host Info = <blockquote> <syntaxhighlight lang="go"> require "os" host, err := os.Hostname() </syntaxhighlight> </blockquote><!-- Host Info --> = User Info = <blockquote> User info is exposed by a struct of passwd info. <syntaxhighlight lang="go"> userinfo, err := user.Lookup("will") if errors.Is(err, user.UnknownUserError) {...} fmt.Println(userinfo.Uid) </syntaxhighlight> </blockquote><!-- User Info -->")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Host Info

require "os"

host, err := os.Hostname()

User Info

User info is exposed by a struct of passwd info.

userinfo, err := user.Lookup("will")

if errors.Is(err, user.UnknownUserError) {...}
fmt.Println(userinfo.Uid)