loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add `io.Closer` guidelines (#29387)

Co-authored-by: Yarden Shoham <git@yardenshoham.com>
(cherry picked from commit ad0a34b492c3d41952ff4648c8bfb7b54c376151)

authored by

KN4CK3R
Yarden Shoham
and committed by
Earl Warren
753f9711 3723caf7

+16 -9
+4
docs/content/contributing/guidelines-backend.en-us.md
··· 101 101 Since there are some packages which use the same package name, it is possible that you find packages like `modules/user`, `models/user`, and `services/user`. When these packages are imported in one Go file, it's difficult to know which package we are using and if it's a variable name or an import name. So, we always recommend to use import aliases. To differ from package variables which are commonly in camelCase, just use **snake_case** for import aliases. 102 102 i.e. `import user_service "code.gitea.io/gitea/services/user"` 103 103 104 + ### Implementing `io.Closer` 105 + 106 + If a type implements `io.Closer`, calling `Close` multiple times must not fail or `panic` but return an error or `nil`. 107 + 104 108 ### Important Gotchas 105 109 106 110 - Never write `x.Update(exemplar)` without an explicit `WHERE` clause:
+4
modules/git/blame.go
··· 115 115 116 116 // Close BlameReader - don't run NextPart after invoking that 117 117 func (r *BlameReader) Close() error { 118 + if r.bufferedReader == nil { 119 + return nil 120 + } 121 + 118 122 err := <-r.done 119 123 r.bufferedReader = nil 120 124 _ = r.reader.Close()
+4 -3
modules/git/repo_base_gogit.go
··· 88 88 } 89 89 90 90 // Close this repository, in particular close the underlying gogitStorage if this is not nil 91 - func (repo *Repository) Close() (err error) { 91 + func (repo *Repository) Close() error { 92 92 if repo == nil || repo.gogitStorage == nil { 93 - return 93 + return nil 94 94 } 95 95 if err := repo.gogitStorage.Close(); err != nil { 96 96 gitealog.Error("Error closing storage: %v", err) 97 97 } 98 + repo.gogitStorage = nil 98 99 repo.LastCommitCache = nil 99 100 repo.tagCache = nil 100 - return 101 + return nil 101 102 } 102 103 103 104 // GoGitRepo gets the go-git repo representation
+2 -2
modules/git/repo_base_nogogit.go
··· 103 103 } 104 104 } 105 105 106 - func (repo *Repository) Close() (err error) { 106 + func (repo *Repository) Close() error { 107 107 if repo == nil { 108 108 return nil 109 109 } ··· 123 123 } 124 124 repo.LastCommitCache = nil 125 125 repo.tagCache = nil 126 - return err 126 + return nil 127 127 }
+1 -1
modules/indexer/internal/bleve/indexer.go
··· 91 91 } 92 92 93 93 func (i *Indexer) Close() { 94 - if i == nil { 94 + if i == nil || i.Indexer == nil { 95 95 return 96 96 } 97 97
-3
modules/indexer/internal/meilisearch/indexer.go
··· 87 87 if i == nil { 88 88 return 89 89 } 90 - if i.Client == nil { 91 - return 92 - } 93 90 i.Client = nil 94 91 }
+1
modules/util/filebuffer/file_backed_buffer.go
··· 149 149 if b.file != nil { 150 150 err := b.file.Close() 151 151 os.Remove(b.file.Name()) 152 + b.file = nil 152 153 return err 153 154 } 154 155 return nil