mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-10-26 09:11:01 +00:00
♻️ Refactor code
🔥 Remove update detection
This commit is contained in:
31
common/template.go
Normal file
31
common/template.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// LoadTemplate 加载模板
|
||||
// templates 模板文件名
|
||||
func LoadTemplate(template string) ([]byte, error) {
|
||||
tPath := filepath.Join("templates", template)
|
||||
if _, err := os.Stat(tPath); err == nil {
|
||||
file, err := os.Open(tPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer func(file *os.File) {
|
||||
if file != nil {
|
||||
_ = file.Close()
|
||||
}
|
||||
}(file)
|
||||
result, err := io.ReadAll(file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
return nil, errors.New("模板文件不存在")
|
||||
}
|
||||
Reference in New Issue
Block a user