#cant use os user normally

10 messages · Page 1 of 1 (latest)

simple zephyr
#
package main

import (
    "fmt"
    "log"
    "os/user"
)

func main() {
    currentUser, err := user.Current()
    if err != nil {
        log.Fatalf(err.Error())
    }

    username := currentUser.Username

    fmt.Printf("Username is: %s", username)
}

and i get

Username is: REVISION-PC\tatamip

instead of

Username is: tatamip
#

Go version - 1.19.3

ionic raven
sinful sand
simple zephyr
#

without domain

simple zephyr
#
package main

import (
    "fmt"
    "log"
    "os/user"
)

func main() {
    currentUser, err := user.Current()
    if err != nil {
        log.Fatalf(err.Error())
    }

    username := currentUser.Name

    fmt.Printf("Username is: %s", username)
}
ionic raven
#

in that case you can try to manipulate the string in order to cut out the domain from currentUser.Username