1
mirror of https://github.com/jlelse/GoBlog synced 2024-06-15 10:27:09 +00:00

Add some missing file closes

This commit is contained in:
Jan-Lukas Else 2023-12-25 10:23:35 +01:00
parent 67ae1662ed
commit 6028c04a09
7 changed files with 14 additions and 13 deletions

2
go.mod
View File

@ -126,7 +126,7 @@ require (
golang.org/x/oauth2 v0.15.0 // indirect
golang.org/x/sys v0.15.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
maunium.net/go/maulogger/v2 v2.4.1 // indirect
willnorris.com/go/webmention v0.0.0-20220108183051-4a23794272f0 // indirect

4
go.sum
View File

@ -378,8 +378,8 @@ google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAs
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -29,5 +29,6 @@ func (a *goBlog) serveFs(f fs.FS, basePath string) http.HandlerFunc {
default:
_, _ = io.Copy(w, file)
}
_ = file.Close()
}
}

12
main.go
View File

@ -67,12 +67,6 @@ func main() {
return
}
// Initialize plugins
if err = app.initPlugins(); err != nil {
app.logErrAndQuit("Failed to init plugins:", err.Error())
return
}
// Healthcheck tool
if len(os.Args) >= 2 && os.Args[1] == "healthcheck" {
// Connect to public address + "/ping" and exit with 0 when successful
@ -97,6 +91,12 @@ func main() {
return
}
// Initialize plugins
if err = app.initPlugins(); err != nil {
app.logErrAndQuit("Failed to init plugins:", err.Error())
return
}
// Start pprof server
if pprofCfg := app.cfg.Pprof; pprofCfg != nil && pprofCfg.Enabled {
go func() {

View File

@ -95,7 +95,7 @@ type highlighting struct{}
// Highlighting is a goldmark.Extender implementation.
var Highlighting = &highlighting{}
var Style = styles.Monokai
var Style = styles.Get("monokai")
// Extend implements goldmark.Extender.
func (*highlighting) Extend(m goldmark.Markdown) {

View File

@ -47,11 +47,9 @@ func (p *plugin) RenderWithDocument(_ plugintypes.RenderContext, doc *goquery.Do
fmt.Println("Failed to open custom css file: ", err.Error())
return
}
defer func() {
_ = f.Close()
}()
err = p.app.CompileAsset("plugincustomcss.css", f)
_ = f.Close()
if err != nil {
fmt.Println("Failed compile custom css: ", err.Error())
return

View File

@ -157,6 +157,7 @@ func (a *goBlog) profileImageHash() string {
return nil, nil
}
_, _ = io.Copy(hash, file)
_ = file.Close()
a.profileImageHashString = fmt.Sprintf("%x", hash.Sum(nil))
return nil, nil
})
@ -194,6 +195,7 @@ func (a *goBlog) serveUpdateProfileImage(w http.ResponseWriter, r *http.Request)
}
_, err = io.Copy(dataFile, file)
_ = file.Close()
_ = dataFile.Close()
if err != nil {
a.serveError(w, r, "Failed to save image", http.StatusBadRequest)
return