New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
net/http: Directory do not need to be close? #12904
Comments
Nope. Line 370. |
package main
import (
"fmt"
"os"
)
func main() {
f, err := os.Open("test")
if err != nil {
return
}
defer func() {
fmt.Println("f.Close", f.Close())
}()
d, err := f.Stat()
if err != nil {
return
}
if d.IsDir() {
ff, err := os.Open("index.html")
if err == nil {
defer func() {
fmt.Println("ff.Close", ff.Close())
}()
f = ff
}
}
} output: |
package main
import (
"fmt"
"os"
)
func main() {
f, err := os.Open("test")
if err != nil {
return
}
defer func() {
fmt.Println("f.Close", f.Close())
}()
d, err := f.Stat()
if err != nil {
return
}
if d.IsDir() {
ff, err := os.Open("index.html")
if err == nil {
fmt.Println("f.Close", f.Close())
f = ff
}
}
} after f = ff defer f.Close() in fact, ff object |
Your example is not the same as the original code, because in this line
the name In this line
the value of |
Thank you. |
https://github.com/golang/go/blob/master/src/net/http/fs.go#L400-L408
before f = ff , f don't need to be f.Close()?
The text was updated successfully, but these errors were encountered: