You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package ProtoController
import (
"bytes"
"dsAutoCode/Model"
"dsAutoCode/Service/ProtoService"
"dsAutoCode/Utils/CommonUtil"
"github.com/gin-gonic/gin"
"log"
"net/http"
"strings"
"text/template"
)
/**
功能:获取骨架的内容
作者:黄海
时间2020-04-24
*/
func getFrameworkContent(interfaceName string) (string, string) {
var operateType string
var tableName string
operateType = ProtoService.GetOperateType(interfaceName)
tableName = strings.Replace(interfaceName, operateType, "", -1)
//调用模板,
filesName := CommonUtil.GetCurrentPath()+"/Controller/ProtoController/Template/ControllerFramework.template"
t, err := template.ParseFiles(filesName)
if err != nil {
log.Fatalln("parse file err:", err)
return "", ""
}
buf := new(bytes.Buffer)
var p = map[string]interface{}{
"tableName": tableName,
}
if err := t.Execute(buf, p); err != nil {
log.Fatal("There was an error:", err.Error())
}
var content = buf.String()
content = CommonUtil.DeleteBlankString(content)
return tableName, content
}
/**
功能生成ControllerFramework层的操作代码
作者:黄海
时间2020-04-23
*/
func CodeControllerFramework(c *gin.Context) {
interfaceName := c.Query("interfaceName")
tableName, content := getFrameworkContent(interfaceName)
c.JSON(http.StatusOK, Model.Res{
Data: content,
Msg: tableName,
CodePath: ProtoService.GetGenereateCodePath("Controller", tableName),
})
}