@@ -42,6 +42,9 @@ const SQLServiceFile = "sqls-service.go.tmpl"
4242const MySQLDaoFile = "mysql-dao.go.tmpl"
4343const SQLModelFile = "sqls-model.go.tmpl"
4444
45+ // common file for common utility functions in controllers
46+ const ControllersCommonFile = "common.go.tmpl"
47+
4548const DaoFile = "dao.go.tmpl"
4649const SQLiteDaoFile = "sqlite-dao.go.tmpl"
4750const MySQLDBConfigFile = "mysql.go.tmpl"
@@ -472,6 +475,15 @@ func (c *Copier) copyNoSQLDBResourceFiles(resourceName string, filePaths []*stri
472475 }
473476 filePaths = append (filePaths , & targetResourceControllerFileName )
474477
478+ // copy controller common file to a generated project
479+ targetResourceControllerCommonFileName := c .NodeDirectoryName + ControllersPath + "/" + ControllersCommonFile
480+ _ , err = utils .CopyFile (targetResourceControllerCommonFileName , c .TemplatesRootPath + ControllersPath + "/" + ControllersCommonFile )
481+ if err != nil {
482+ log .Debugf ("error copying controller utils file: %v" , err )
483+ return nil , err
484+ }
485+ filePaths = append (filePaths , & targetResourceControllerCommonFileName )
486+
475487 // copy model files to a generated project
476488 targetResourceModelFileName := c .NodeDirectoryName + ModelsPath + "/" + resourceName + "-" + strings .Replace (NoSQLModelFile , "nosqls-" , "" , 1 )
477489 _ , err = utils .CopyFile (targetResourceModelFileName , c .TemplatesRootPath + ModelsPath + "/" + NoSQLModelFile )
@@ -515,6 +527,15 @@ func (c *Copier) copySQLDBResourceFiles(resourceName string, filePaths []*string
515527 }
516528 filePaths = append (filePaths , & targetResourceControllerFileName )
517529
530+ // copy controller common file to a generated project
531+ targetResourceControllerCommonFileName := c .NodeDirectoryName + ControllersPath + "/" + ControllersCommonFile
532+ _ , err = utils .CopyFile (targetResourceControllerCommonFileName , c .TemplatesRootPath + ControllersPath + "/" + ControllersCommonFile )
533+ if err != nil {
534+ log .Debugf ("error copying controller utils file: %v" , err )
535+ return nil , err
536+ }
537+ filePaths = append (filePaths , & targetResourceControllerCommonFileName )
538+
518539 // copy service files to a generated project
519540 targetResourceServiceFileName := c .NodeDirectoryName + ServicesPath + "/" + resourceName + "-" + strings .Replace (SQLServiceFile , "sqls-" , "" , 1 )
520541 _ , err = utils .CopyFile (targetResourceServiceFileName , c .TemplatesRootPath + ServicesPath + "/" + SQLServiceFile )
0 commit comments