Documentation ¶
Index ¶
- Constants
- Variables
- func AddTemplateByDir(root string, namespaceSuffix string, funcMap template.FuncMap, ...) (templateMap map[string]*template.Template, err error)
- func AddTemplateByFS(fsys fs.FS, root string, namespaceSuffix string, funcMap template.FuncMap, ...) (templateMap map[string]*template.Template, err error)
- func AddTemplateByStr(namespace string, content string, funcMap template.FuncMap, leftDelim string, ...) (t *template.Template, err error)
- func BatchInsertUpdateDelSQL(args *BatchInsertUpdateDelSQLArgs)
- func ConvertStruct(from interface{}, to interface{})
- func CurrentTime(tplEntity TplEntityInterface) (string, error)
- func DBBatchExec(db func() *gorm.DB, sqlMap map[string]string) (err error)
- func DBBatchSave(sqlRepository func() *RepositorySQL, db func() *gorm.DB, ...) (err error)
- func DBCount(sqlRepository func() *RepositorySQL, db func() *gorm.DB, ...) (err error)
- func DBCreateTable(getrepositorySQL func() *RepositorySQL)
- func DBExec(sqlRepository func() *RepositorySQL, db func() *gorm.DB, ...) (err error)
- func DBRawScan(sqlRepository func() *RepositorySQL, db func() *gorm.DB, ...) (err error)
- func DBTryFind(sqlRepository func() *RepositorySQL, db func() *gorm.DB, ...) (err error)
- func ExecTpl(dataVolume TplEntityInterface, fullname string) (output string, err error)
- func FileName2Namespace(filename string, root string) (namespace string)
- func Flight(sqlStr string, output interface{}, fn func() (interface{}, error)) (err error)
- func GetDb() *gorm.DB
- func GetMD5LOWER(s string) string
- func GetTplFilesByDir(dir string, namespaceSuffix string) (allFileList []string, err error)
- func GetTplFilesByFS(fsys fs.FS, dir string, namespaceSuffix string) (allFileList []string, err error)
- func Glob(fsys fs.FS, pattern string) ([]string, error)
- func GlobDirectory(dir string, pattern string) ([]string, error)
- func In(tplEntity TplEntityInterface, data interface{}) (str string, err error)
- func InitDB() *gorm.DB
- func InitRepositorySQL()
- func Model2TplEntity(from interface{}, to TplEntityInterface)
- func NewPreComma() *preComma
- func PermanentTime(tplEntity TplEntityInterface) (string, error)
- func SnakeCase(name string) string
- func SpellFullname(namespace string, name string) (fullname string)
- func SplitFullname(fullname string) (namespace string, name string)
- func StandardizeSpaces(s string) string
- func Statement2SQL(sqlStatement string, vars []interface{}) (sqlStr string)
- func ToCamel(name string) string
- func ToEOF(s string) string
- func ToLowerCamel(name string) string
- func TplOutput(dataVolume TplEntityInterface, tplEntity TplEntityInterface) (output string, err error)
- func TrimSpaces(s string) string
- func WrapDBExecSQL(db func() *gorm.DB) func(sqlRowList []*SQLRow) (err error)
- func WrapDBScanSQL(db func() *gorm.DB, throwNotFoundErr bool) func(sqlRowList []*SQLRow) (err error)
- func ZeroTime(tplEntity TplEntityInterface) (string, error)
- type BatchInsertUpdateDelSQLArgs
- type DBBatchSaveArgs
- type RepositorySQL
- func (r *RepositorySQL) AddByDir(root string, funcMap template.FuncMap) (err error)
- func (r *RepositorySQL) AddByFS(fsys fs.FS, root string, funcMap template.FuncMap) (err error)
- func (r *RepositorySQL) AddByNamespace(namespace string, content string, funcMap template.FuncMap) (err error)
- func (r *RepositorySQL) DefineResult2SQLRow(defineResult TPLDefine) (sqlRow *SQLRow, err error)
- func (r *RepositorySQL) GetByNamespace(namespace string, data TplEntityInterface) (sqlRowList []*SQLRow, err error)
- func (r *RepositorySQL) GetDDLNamespace() (ddlNamespace string, err error)
- func (r *RepositorySQL) GetDDLSQL() (ddlSQLRowList []*SQLRow, err error)
- func (r *RepositorySQL) GetSQL(t TplEntityInterface) (*SQLRow, error)
- func (r *RepositorySQL) GetSQLRef(t TplEntityInterface, sqlStr *string) (err error)
- func (r *RepositorySQL) NewSQLChain() *SQLChain
- type RepositoryTemplate
- type SQLChain
- func (s *SQLChain) AddSQL(namespace string, name string, sql string, result interface{})
- func (s *SQLChain) Error() (err error)
- func (s *SQLChain) Exec(fn func(sqlRowList []*SQLRow) (e error)) (err error)
- func (s *SQLChain) ParseSQL(t TplEntityInterface, result interface{}) *SQLChain
- func (s *SQLChain) SQLRows() (sqlRowList []*SQLRow, err error)
- func (s *SQLChain) Scan(fn func(sqlRowList []*SQLRow) (e error)) (err error)
- func (s *SQLChain) SetError(err error)
- type SQLRow
- type TPLDefine
- func ExecuteNamespaceTemplate(templateMap map[string]*template.Template, namespace string, ...) (tplDefineList []*TPLDefine, err error)
- func ExecuteTemplate(templateMap map[string]*template.Template, fullname string, ...) (tplDefine *TPLDefine, err error)
- func ExecuteTemplateTry(templateMap map[string]*template.Template, fullname string, ...) (tplDefine *TPLDefine, err error)
- type TplEmptyEntity
- func (v *TplEmptyEntity) GetDynamicValus() (values map[string]interface{})
- func (v *TplEmptyEntity) GetSQLRow() (sqlRow *SQLRow, err error)
- func (v *TplEmptyEntity) GetValue(key string) (value interface{}, ok bool)
- func (v *TplEmptyEntity) SetValue(key string, value interface{})
- func (v *TplEmptyEntity) TplName() string
- func (v *TplEmptyEntity) TplType() string
- type TplEntityInterface
Constants ¶
const ( EOF = "\n" WINDOW_EOF = "\r\n" HTTP_HEAD_BODY_DELIM = EOF + EOF )
const TEMPLATE_MAP_KEY = "_templateMap"
const URI_KEY = "__URI__" // 记录资源地址key(curl 请求地址、db 连接地址等)
Variables ¶
var CURLNamespaceSuffix = "curl"
var ConfigNamespaceSuffix = "config"
var DB_SOURCE = ""
var DDLNamespaceSuffix = "ddl"
var LeftDelim = "{{"
var MetaNamespaceSuffix = "meta"
var RepositoryFS *embed.FS
实际使用时,需要初始化该变量
var RightDelim = "}}"
var SQLNamespaceSuffix = "sql"
var TPlSuffix = ".tpl"
var TemplateDir = "template"
var TemplatefuncMap = template.FuncMap{ "zeroTime": ZeroTime, "currentTime": CurrentTime, "permanentTime": PermanentTime, "contains": strings.Contains, "newPreComma": NewPreComma, "in": In, "toCamel": ToCamel, "toLowerCamel": ToLowerCamel, "snakeCase": SnakeCase, "tplOutput": TplOutput, }
Functions ¶
func AddTemplateByDir ¶ added in v2.0.1
func AddTemplateByFS ¶ added in v2.0.1
func AddTemplateByStr ¶ added in v2.0.1
func BatchInsertUpdateDelSQL ¶
func BatchInsertUpdateDelSQL(args *BatchInsertUpdateDelSQLArgs)
func CurrentTime ¶
func CurrentTime(tplEntity TplEntityInterface) (string, error)
func DBBatchSave ¶
func DBBatchSave(sqlRepository func() *RepositorySQL, db func() *gorm.DB, getByIDsEntity TplEntityInterface, args *DBBatchSaveArgs) (err error)
func DBCount ¶
func DBCount(sqlRepository func() *RepositorySQL, db func() *gorm.DB, entity TplEntityInterface, count *int) (err error)
func DBCreateTable ¶
func DBCreateTable(getrepositorySQL func() *RepositorySQL)
DBCreateTable 初始化数据表
func DBExec ¶
func DBExec(sqlRepository func() *RepositorySQL, db func() *gorm.DB, entity TplEntityInterface) (err error)
func DBRawScan ¶
func DBRawScan(sqlRepository func() *RepositorySQL, db func() *gorm.DB, entity TplEntityInterface, output interface{}) (err error)
func DBTryFind ¶
func DBTryFind(sqlRepository func() *RepositorySQL, db func() *gorm.DB, entity TplEntityInterface, output interface{}) (err error)
func ExecTpl ¶ added in v2.0.1
func ExecTpl(dataVolume TplEntityInterface, fullname string) (output string, err error)
TplOutput 模板中执行模板,获取数据时使用 gqttool 生成的entity 会调用该方法,实现 TplEntityInterface 接口
func FileName2Namespace ¶ added in v2.0.1
func GetMD5LOWER ¶
func GetTplFilesByDir ¶ added in v2.0.1
GetTplFilesByDir get current and reverse dir tpl file
func GetTplFilesByFS ¶ added in v2.0.1
func Glob ¶ added in v2.0.1
Glob adds double-star support to the core path/filepath Glob function. It's useful when your globs might have double-stars, but you're not sure.
func GlobDirectory ¶ added in v2.0.1
func In ¶
func In(tplEntity TplEntityInterface, data interface{}) (str string, err error)
func InitRepositorySQL ¶
func InitRepositorySQL()
func Model2TplEntity ¶
func Model2TplEntity(from interface{}, to TplEntityInterface)
Model2Entity copy model to entity ,some times input used to insert and update ,in this case input mybe model, copy model value to insertEntity and updateEntity
func NewPreComma ¶
func NewPreComma() *preComma
func PermanentTime ¶
func PermanentTime(tplEntity TplEntityInterface) (string, error)
func SpellFullname ¶ added in v2.0.1
func SplitFullname ¶ added in v2.0.1
func StandardizeSpaces ¶ added in v2.0.1
func Statement2SQL ¶ added in v2.0.1
func ToLowerCamel ¶ added in v2.0.1
func TplOutput ¶
func TplOutput(dataVolume TplEntityInterface, tplEntity TplEntityInterface) (output string, err error)
func WrapDBScanSQL ¶
func ZeroTime ¶
func ZeroTime(tplEntity TplEntityInterface) (string, error)
Types ¶
type BatchInsertUpdateDelSQLArgs ¶
type BatchInsertUpdateDelSQLArgs struct { ModelList interface{} DBModelList interface{} PrimaryKeyCamel string UpdateEntity TplEntityInterface InsertEntity TplEntityInterface DelEntity TplEntityInterface SqlChain *SQLChain }
type DBBatchSaveArgs ¶
type DBBatchSaveArgs struct { ModelList interface{} PrimaryKeyCamel string UpdateEntity TplEntityInterface // 无需填充 InsertEntity TplEntityInterface // 无需填充 DelEntity TplEntityInterface // 无需填充 }
type RepositorySQL ¶
type RepositorySQL struct {
// contains filtered or unexported fields
}
RepositorySQL stores SQL templates.
func GetRepositorySQL ¶
func GetRepositorySQL() *RepositorySQL
func NewRepositorySQL ¶
func NewRepositorySQL() *RepositorySQL
NewRepositorySQL create a new Repository.
func (*RepositorySQL) AddByDir ¶
func (r *RepositorySQL) AddByDir(root string, funcMap template.FuncMap) (err error)
func (*RepositorySQL) AddByNamespace ¶
func (*RepositorySQL) DefineResult2SQLRow ¶
func (r *RepositorySQL) DefineResult2SQLRow(defineResult TPLDefine) (sqlRow *SQLRow, err error)
func (*RepositorySQL) GetByNamespace ¶
func (r *RepositorySQL) GetByNamespace(namespace string, data TplEntityInterface) (sqlRowList []*SQLRow, err error)
GetByNamespace get all template under namespace
func (*RepositorySQL) GetDDLNamespace ¶
func (r *RepositorySQL) GetDDLNamespace() (ddlNamespace string, err error)
func (*RepositorySQL) GetDDLSQL ¶
func (r *RepositorySQL) GetDDLSQL() (ddlSQLRowList []*SQLRow, err error)
func (*RepositorySQL) GetSQL ¶
func (r *RepositorySQL) GetSQL(t TplEntityInterface) (*SQLRow, error)
将模板名称,模板中的变量,封装到结构体中,使用结构体访问,避免拼写错误以及分散的硬编码,可以配合 gqttool 自动生成响应的结构体
func (*RepositorySQL) GetSQLRef ¶
func (r *RepositorySQL) GetSQLRef(t TplEntityInterface, sqlStr *string) (err error)
GetSQLByTplEntityRef 支持只返回error 函数签名
func (*RepositorySQL) NewSQLChain ¶
func (r *RepositorySQL) NewSQLChain() *SQLChain
type RepositoryTemplate ¶ added in v2.0.1
type RepositoryTemplate struct {
// contains filtered or unexported fields
}
RepositoryTemplate stores templates.
func NewRepositoryTemplate ¶ added in v2.0.1
func NewRepositoryTemplate() *RepositoryTemplate
NewRepositoryTemplate create a new RepositoryTemplate.
type SQLChain ¶
type SQLChain struct {
// contains filtered or unexported fields
}
func (*SQLChain) ParseSQL ¶
func (s *SQLChain) ParseSQL(t TplEntityInterface, result interface{}) *SQLChain
type TPLDefine ¶ added in v2.0.1
func ExecuteNamespaceTemplate ¶ added in v2.0.1
func ExecuteNamespaceTemplate(templateMap map[string]*template.Template, namespace string, tplEntity TplEntityInterface) (tplDefineList []*TPLDefine, err error)
ExecuteNamespaceTemplate execute all template under namespace
func ExecuteTemplate ¶ added in v2.0.1
func ExecuteTemplate(templateMap map[string]*template.Template, fullname string, tplEntity TplEntityInterface) (tplDefine *TPLDefine, err error)
ExecuteNamespaceTemplate execute all template under namespace
func ExecuteTemplateTry ¶ added in v2.0.1
func ExecuteTemplateTry(templateMap map[string]*template.Template, fullname string, tplEntity TplEntityInterface) (tplDefine *TPLDefine, err error)
ExecuteTemplateTry 找不到模板的时候,返回null,不报错(curl 模板需要先执行xxxBody_模板)
type TplEmptyEntity ¶ added in v2.0.1
type TplEmptyEntity map[string]interface{}
func (*TplEmptyEntity) GetDynamicValus ¶ added in v2.0.1
func (v *TplEmptyEntity) GetDynamicValus() (values map[string]interface{})
func (*TplEmptyEntity) GetSQLRow ¶ added in v2.0.1
func (v *TplEmptyEntity) GetSQLRow() (sqlRow *SQLRow, err error)
func (*TplEmptyEntity) GetValue ¶ added in v2.0.1
func (v *TplEmptyEntity) GetValue(key string) (value interface{}, ok bool)
func (*TplEmptyEntity) SetValue ¶ added in v2.0.1
func (v *TplEmptyEntity) SetValue(key string, value interface{})
func (*TplEmptyEntity) TplName ¶ added in v2.0.1
func (v *TplEmptyEntity) TplName() string
func (*TplEmptyEntity) TplType ¶ added in v2.0.1
func (v *TplEmptyEntity) TplType() string
type TplEntityInterface ¶ added in v2.0.1
type TplEntityInterface interface { TplName() string TplType() string // 返回 TPL_DEFINE_TYPE 类型,方便后续根据类型获取资源(db、curl) 自动获取数据 SetValue(key string, value interface{}) GetValue(key string) (value interface{}, ok bool) GetDynamicValus() (values map[string]interface{}) GetSQLRow() (sqlRow *SQLRow, err error) }
TplEntityInterface 模板参数对象,由于sql、curl经常需要在模板中增加数据,所以直接在模板输入实体接口融合TplEntityInterface 接口功能,实体包含隐藏字段类型tplEntityMap,即可实现TplEntityInterface 功能