The problem is that the function’s return type is already *os.File (rather than io.WriteCloser or some other interface), so the type assertion is pointless.
Andy > On May 7, 2020, at 5:09 AM, André kouamé <kouameandr...@gmail.com> wrote: > > Hi, > > 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 > > -- > 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 > <mailto:golang-nuts+unsubscr...@googlegroups.com>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/e88406f6-7646-4cd9-9e0f-dfe6eae2581f%40googlegroups.com > > <https://groups.google.com/d/msgid/golang-nuts/e88406f6-7646-4cd9-9e0f-dfe6eae2581f%40googlegroups.com?utm_medium=email&utm_source=footer>. -- 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/BC68789B-21AE-4708-90A3-38FFAC3065B8%40gmail.com.