mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-06-16 20:23:19 +08:00
28 lines
471 B
Go
28 lines
471 B
Go
package common
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
func LoadTemplate(templatePath string) ([]byte, error) {
|
|
if _, err := os.Stat(templatePath); err == nil {
|
|
file, err := os.Open(templatePath)
|
|
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("模板文件不存在")
|
|
}
|