Skip to content

Commit

Permalink
[strutil] Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
andyone committed Feb 12, 2024
1 parent 597b938 commit 3afb72c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions system/info_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func GetOSInfo() (*OSInfo, error) {
info := &OSInfo{}

for _, line := range strings.Split(string(versionData), "\n") {
name := strutil.ReadField(line, 0, false, ":")
value := strutil.ReadField(line, 1, false, ":")
name := strutil.ReadField(line, 0, false, ':')
value := strutil.ReadField(line, 1, false, ':')
value = strings.Trim(value, " \r\t\n")

switch name {
Expand Down
14 changes: 7 additions & 7 deletions system/user_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,20 @@ func getUserInfo(name string) (*User, error) {

for scanner.Scan() {
line := scanner.Text()
field := strutil.ReadField(line, 0, false, ":")
field := strutil.ReadField(line, 0, false, ':')

switch field {
case "UniqueID":
user.UID, err = strconv.Atoi(strings.TrimSpace(strutil.ReadField(line, 1, false, ":")))
user.UID, err = strconv.Atoi(strings.TrimSpace(strutil.ReadField(line, 1, false, ':')))
case "PrimaryGroupID":
user.GID, err = strconv.Atoi(strings.TrimSpace(strutil.ReadField(line, 1, false, ":")))
user.GID, err = strconv.Atoi(strings.TrimSpace(strutil.ReadField(line, 1, false, ':')))
case "NFSHomeDirectory":
user.HomeDir = strutil.ReadField(
strings.TrimSpace(strutil.ReadField(line, 1, false, ":")),
0, false, " ",
strings.TrimSpace(strutil.ReadField(line, 1, false, ':')),
0, false, ' ',
)
case "UserShell":
user.Shell = strings.TrimSpace(strutil.ReadField(line, 1, false, ":"))
user.Shell = strings.TrimSpace(strutil.ReadField(line, 1, false, ':'))
}

if err != nil {
Expand All @@ -93,7 +93,7 @@ func getGroupInfo(name string) (*Group, error) {
group := &Group{Name: name}
data := string(out)

group.GID, err = strconv.Atoi(strings.TrimSpace(strutil.ReadField(data, 1, false, ":")))
group.GID, err = strconv.Atoi(strings.TrimSpace(strutil.ReadField(data, 1, false, ':')))

if err != nil {
return nil, fmt.Errorf("Can't parse PrimaryGroupID field value: %v", err)
Expand Down

0 comments on commit 3afb72c

Please sign in to comment.