I figured out this issue. I was calling the struct and needed to call one 
specific element of the struct. Then I assign it to a string.

user, err := user.Current()
    if err != nil {
        log.Fatal(err)
    }
    var testuser string = string(user.Username)
        if testuser == "root" || testuser == "someuser" {
                fmt.Println("You are currently logged in as:" + testuser 
+":")
        }else {
        fmt.Println("You need to be root or someuser to run this program")
        os.Exit(1)
        }


On Monday, March 5, 2018 at 11:28:54 AM UTC-7, John Mizell wrote:
>
>
> Here is the the program
> package main
>
> import (
>         "fmt"
>         "log"
>         "os/user"
> )
>
> func main() {
>     username, err := user.Current()
>     if err != nil {
>         log.Fatal(err)
>     }
>         if username != "root" || username != "someuser" {
>                 fmt.Println("You are currently logged in as:" + username)
>                 fmt.Println("You need to be root or someuser")
>         }
>
>
> }
>
> Here is the output
> go run user.go
> # command-line-arguments
> ./user.go:14:14: invalid operation: username != "root" (mismatched types 
> *user.User and string)
> ./user.go:14:36: invalid operation: username != "someuser" (mismatched 
> types *user.User and string)
> ./user.go:15:53: invalid operation: "You are currently logged in as:" + 
> username (mismatched types string and *user.User)
>
> I am not sure how to handle mismatched types string and *user.User. 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to