mirror of
https://github.com/nitezs/sub2clash.git
synced 2024-12-24 11:44:42 -05:00
37 lines
647 B
Go
37 lines
647 B
Go
package utils
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
// LoadTemplate 加载模板
|
|
// template 模板文件名
|
|
func LoadTemplate(template string) (string, error) {
|
|
tPath := filepath.Join("templates", template)
|
|
if _, err := os.Stat(tPath); err == nil {
|
|
file, err := os.Open(tPath)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer func(file *os.File) {
|
|
err := file.Close()
|
|
if err != nil {
|
|
fmt.Println(err)
|
|
}
|
|
}(file)
|
|
result, err := io.ReadAll(file)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(result), nil
|
|
}
|
|
return "", errors.New("模板文件不存在")
|
|
}
|