是否需要关闭文件?

When i use golang gin, read file data using:

file, fileHeader, err:=ctx.Request.FormFile("blabla...")

Do I need to write these:

defer file.Close()

?

I jump to the source code, it says:

// Open opens and returns the FileHeader's associated File.
func (fh *FileHeader) Open() (File, error) {
        if b := fh.content; b != nil {
                r := io.NewSectionReader(bytes.NewReader(b), 0, int64(len(b)))
                fmt.Printf("TODDLINE:152
")
                fmt.Printf("TODDLINE:154:fmpfile:%#v
", fh.tmpfile)
                fmt.Printf("TODDLINE:154:Filename:%#v
", fh.Filename)
                return sectionReadCloser{r}, nil
        }
        fmt.Printf("TODDLINE:155
")
        return os.Open(fh.tmpfile)
}

If it uses os.Open, I guess I must close the file, but if it retuns the sectionReadCloser{r}, the Close function shows like this:

func (rc sectionReadCloser) Close() error {
        return nil
}

The close function of seciontReadCloser doesn't do anything. And I find that it does return the sectionReadCloser{r}. I guess I should close the file, but I still want to know when it will return the os.Open. I will keep going to read the source code and try to understand it. It would be nice if someone gives me some advice.

If the file returned implements io.Closer (i.e., if it has a Close method), assume you are responsible for closing it unless the documentation explicitly states otherwise.