* André kouamé <kouameandr...@gmail.com> [200507 12:57]: > I want to check, if the value return by my function has the type *os.File > This my code : > func createFile(filename string) (*os.File, error) { > f, err := os.OpenFile(filename, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) > return f, err > > } > //Test code > filename := "testfile" > f, _ := createFile(filename) > c := &f.(*os.File) > fmt.Println(c) > Error return : > invalid type assertion: f.(*os.File) (non-interface type *os.File on left) > Process exiting with code: 1
The value being coerced must be an interface type. «f» above is of type «*os.File», which is a concrete type. This playground link shows an example of what I think you want: https://play.golang.org/p/AILqjXUK0zx Note that «rdr» is of type «io.Reader», which is an interface that «*os.File» implements. ...Marvin -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/20200507174509.bgqwrkx674gsnfvn%40basil.wdw.