Skip to content

Commit 56d7009

Browse files
committed
chore: move out some funcs
1 parent 2dc4f80 commit 56d7009

File tree

3 files changed

+26
-50
lines changed

3 files changed

+26
-50
lines changed

modules/options/base.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,37 @@ import (
77
"fmt"
88
"io/fs"
99
"os"
10+
"path"
1011
"path/filepath"
1112

1213
"code.gitea.io/gitea/modules/util"
1314
)
1415

16+
// Locale reads the content of a specific locale from static/bindata or custom path.
17+
func Locale(name string) ([]byte, error) {
18+
return fileFromDir(path.Join("locale", name))
19+
}
20+
21+
// Readme reads the content of a specific readme from static/bindata or custom path.
22+
func Readme(name string) ([]byte, error) {
23+
return fileFromDir(path.Join("readme", name))
24+
}
25+
26+
// Gitignore reads the content of a gitignore locale from static/bindata or custom path.
27+
func Gitignore(name string) ([]byte, error) {
28+
return fileFromDir(path.Join("gitignore", name))
29+
}
30+
31+
// License reads the content of a specific license from static/bindata or custom path.
32+
func License(name string) ([]byte, error) {
33+
return fileFromDir(path.Join("license", name))
34+
}
35+
36+
// Labels reads the content of a specific labels from static/bindata or custom path.
37+
func Labels(name string) ([]byte, error) {
38+
return fileFromDir(path.Join("label", name))
39+
}
40+
1541
func walkAssetDir(root string, callback func(path, name string, d fs.DirEntry, err error) error) error {
1642
if err := filepath.WalkDir(root, func(path string, d fs.DirEntry, err error) error {
1743
// name is the path relative to the root

modules/options/dynamic.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ func Dir(name string) ([]string, error) {
6060
return directories.AddAndGet(name, result), nil
6161
}
6262

63-
// Locale reads the content of a specific locale from static or custom path.
64-
func Locale(name string) ([]byte, error) {
65-
return fileFromDir(path.Join("locale", name))
66-
}
67-
6863
// WalkLocales reads the content of a specific locale from static or custom path.
6964
func WalkLocales(callback func(path, name string, d fs.DirEntry, err error) error) error {
7065
if err := walkAssetDir(filepath.Join(setting.StaticRootPath, "options", "locale"), callback); err != nil && !os.IsNotExist(err) {
@@ -77,26 +72,6 @@ func WalkLocales(callback func(path, name string, d fs.DirEntry, err error) erro
7772
return nil
7873
}
7974

80-
// Readme reads the content of a specific readme from static or custom path.
81-
func Readme(name string) ([]byte, error) {
82-
return fileFromDir(path.Join("readme", name))
83-
}
84-
85-
// Gitignore reads the content of a specific gitignore from static or custom path.
86-
func Gitignore(name string) ([]byte, error) {
87-
return fileFromDir(path.Join("gitignore", name))
88-
}
89-
90-
// License reads the content of a specific license from static or custom path.
91-
func License(name string) ([]byte, error) {
92-
return fileFromDir(path.Join("license", name))
93-
}
94-
95-
// Labels reads the content of a specific labels from static or custom path.
96-
func Labels(name string) ([]byte, error) {
97-
return fileFromDir(path.Join("label", name))
98-
}
99-
10075
// fileFromDir is a helper to read files from static or custom path.
10176
func fileFromDir(name string) ([]byte, error) {
10277
customPath := path.Join(setting.CustomPath, "options", name)

modules/options/static.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ func AssetDir(dirName string) ([]string, error) {
6969
return results, nil
7070
}
7171

72-
// Locale reads the content of a specific locale from bindata or custom path.
73-
func Locale(name string) ([]byte, error) {
74-
return fileFromDir(path.Join("locale", name))
75-
}
76-
7772
// WalkLocales reads the content of a specific locale from static or custom path.
7873
func WalkLocales(callback func(path, name string, d fs.DirEntry, err error) error) error {
7974
if err := walkAssetDir(filepath.Join(setting.CustomPath, "options", "locale"), callback); err != nil && !os.IsNotExist(err) {
@@ -82,26 +77,6 @@ func WalkLocales(callback func(path, name string, d fs.DirEntry, err error) erro
8277
return nil
8378
}
8479

85-
// Readme reads the content of a specific readme from bindata or custom path.
86-
func Readme(name string) ([]byte, error) {
87-
return fileFromDir(path.Join("readme", name))
88-
}
89-
90-
// Gitignore reads the content of a gitignore locale from bindata or custom path.
91-
func Gitignore(name string) ([]byte, error) {
92-
return fileFromDir(path.Join("gitignore", name))
93-
}
94-
95-
// License reads the content of a specific license from bindata or custom path.
96-
func License(name string) ([]byte, error) {
97-
return fileFromDir(path.Join("license", name))
98-
}
99-
100-
// Labels reads the content of a specific labels from static or custom path.
101-
func Labels(name string) ([]byte, error) {
102-
return fileFromDir(path.Join("label", name))
103-
}
104-
10580
// fileFromDir is a helper to read files from bindata or custom path.
10681
func fileFromDir(name string) ([]byte, error) {
10782
customPath := path.Join(setting.CustomPath, "options", name)

0 commit comments

Comments
 (0)