The beautiful thing about Go is that it is statically typed,
so you don't need to check if your function returned an *os.File.
The compiler already did it  for you....

On Thursday, 7 May 2020 17:57:05 UTC+1, André kouamé 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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/b67843f8-1a87-4feb-bd01-3fc85951c3ea%40googlegroups.com.

Reply via email to