package core import ( "fmt" "git.diulo.com/mogfee/kit/mysql/ddl" "git.diulo.com/mogfee/kit/stringx" "html/template" "io" "strings" ) func SaveFile(w io.Writer, templateContent string, table *ddl.Table) error { tmp, err := template.New("").Funcs(map[string]any{ "UpperType": func(str string) string { return stringx.Ucfirst(ddl.GoName(str)) }, "LowerType": func(str string) string { if str == "type" { str = "vtype" } return stringx.Lcfirst(ddl.GoName(str)) }, "UpdateColumn": func(columns []*ddl.TableColumn) string { arr := []string{} for _, v := range columns { arr = append(arr, fmt.Sprintf("%s=?", v.Name)) } return strings.Join(arr, " and ") }, }).Parse(templateContent) if err != nil { return err } return tmp.Execute(w, table) }