schangxiang@126.com
2025-05-07 cace264ad9d86a7831099810b079da1141957add
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package controllers
 
import (
    "app/dto"
    "app/service"
    "app/utils"
    "net/http"
    "os"
    "path/filepath"
 
    "github.com/gin-gonic/gin"
)
 
// HomeHandler 处理首页请求
func HomeHandler(c *gin.Context) {
    c.JSON(http.StatusOK, gin.H{
        "message": "Hello, World!",
    })
}
 
/**
* 读取文件
**/
func FileHandler(c *gin.Context) {
    query := c.Request.URL.Query()
    absPath, err := filepath.Abs("../" + query.Get("name"))
    if err != nil {
        c.JSON(http.StatusOK, gin.H{
            "message": err,
        })
    } else {
        path := filepath.ToSlash(absPath)
        envLocal, err := os.ReadFile(path)
        if err != nil {
            c.JSON(http.StatusOK, gin.H{
                "message": err,
            })
        } else {
            c.JSON(http.StatusOK, gin.H{
                "data": string(envLocal),
            })
        }
    }
}
 
// 创建组件
func CreateWidget(c *gin.Context) {
    var body dto.RequestBody
    err := c.ShouldBindJSON(&body)
    if err != nil {
        utils.HandlerErr(c, err)
        return
    }
    service.CreateService(c, body)
 
}