Подготовить HY2XS к production-сборке

This commit is contained in:
2026-04-25 23:13:12 +05:00
commit 84a4e94567
277 changed files with 26513 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
package util
import (
"encoding/json"
"errors"
"github.com/sirupsen/logrus"
"gopkg.in/yaml.v3"
"hy2xs-admin/model/constant"
"os"
)
// ExportFile t 0/json 1/yaml
func ExportFile(filePath string, data any, t int) error {
file, err := os.Create(filePath)
if err != nil {
logrus.Errorf("ExportFile create file err filePath: %s err: %v", filePath, err)
return errors.New(constant.SysError)
}
defer file.Close()
var bytes []byte
if t == 0 {
bytes, err = json.MarshalIndent(data, "", " ")
if err != nil {
logrus.Errorf("ExportFile Marshal json err filePath: %s err: %v", filePath, err)
return errors.New(constant.SysError)
}
} else if t == 1 {
bytes, err = yaml.Marshal(&data)
if err != nil {
logrus.Errorf("ExportFile Marshal yaml err filePath: %s err: %v", filePath, err)
return errors.New(constant.SysError)
}
}
_, err = file.Write(bytes)
if err != nil {
logrus.Errorf("ExportFile writer WriteString err filePath: %s err: %v", filePath, err)
return errors.New(constant.SysError)
}
return nil
}