-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs02.go
37 lines (28 loc) · 956 Bytes
/
structs02.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/* RZFeeser | Alta3 Research
Create a struct type named Userdata
to track user information */
package main
import (
"fmt"
"os/user"
)
type Userdata struct {
na string // user id
un string // username
hd string // home directory
em string // email
}
func main() {
// user.Current() is from import os/user - get info about "current system user"
user, err := user.Current() // returns user and error
if err != nil {
panic(err)
}
// create a struct named currentUser
currentUser := Userdata{user.Uid, user.Username, user.HomeDir, "rzfeeser@example.com"}
// recall currentUser
fmt.Println("User id:", currentUser.na) // recall current user id
fmt.Println("Username:", currentUser.un) // recall username
fmt.Println("Home Directory:", currentUser.hd) // recall homedirectory
fmt.Println("Email:", currentUser.em) // recall email
}