package core import ( "fmt" "os" "strings" ) func VarsFile(savePath string) error { saveFileName := fmt.Sprintf("%s/vars.go", strings.TrimRight(savePath, "/")) return os.WriteFile(saveFileName, []byte(` package model import ( "git.diulo.com/mogfee/kit/errors" "gorm.io/gorm" ) var ErrNotFound = errors.BadRequest("DB_NOT_FOUND", "数据不存在") var ErrIdRequest = errors.BadRequest("DB_ID_REQUIRED", "id不能为空") func IsErrNotFound(err error) bool { return errors.Reason(err) == "DB_NOT_FOUND" } func IsErrIdRequest(err error) bool { return errors.Reason(err) == "DB_ID_REQUIRED" } func findResultWithError[T any](data T, err error) (T, error) { switch err { case nil: return data, nil case gorm.ErrRecordNotFound: return data, ErrNotFound default: return data, err } } func GetPage(page int32, size int32) (offset int, pageSize int) { if page <= 1 { page = 1 } offset = int((page - 1) * size) return offset, int(size) } `), os.ModePerm) }