Home Go err: cannot use cur (type *user.User) as type string in argument to f.WriteString
Reply: 0

Go err: cannot use cur (type *user.User) as type string in argument to f.WriteString

user694
1#
user694 Published in May 24, 2018, 4:01 pm

How do I convert data to a string type? I need to write down the data I need to the file which is either not a variable, how do I do it?

Code:

package main

import "os"
import "os/user"
import "encoding/json"

func main(){
    f, err := os.OpenFile("test.txt", os.O_APPEND|os.O_WRONLY, 0600)
    if err != nil {
        panic(err)
    }
    defer f.Close()

    cur, err := user.Current()
    if err != nil {

    } else {


        if _, err = f.WriteString(cur); err != nil {
        panic(err)
        }
    }
}

I do not need to use the cur.Username field. Only a variable.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.318192 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO