MCPcopy Create free account
hub / github.com/LeoninCS/DevDesk / NewHandler

Function NewHandler

backend/internal/handler/handler.go:11–92  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9)
10
11func NewHandler() http.Handler {
12 r := gin.Default()
13 // Limit upload body size; keep it small for HTML hosting needs
14 r.MaxMultipartMemory = 2 << 20
15
16 // ===== CORS 中间件(前后端联调必须要有)=====
17 r.Use(func(c *gin.Context) {
18 origin := c.Request.Header.Get("Origin")
19 if origin != "" {
20 c.Header("Access-Control-Allow-Origin", origin)
21 c.Header("Access-Control-Allow-Credentials", "true")
22 c.Header("Access-Control-Allow-Headers", "Content-Type, Authorization")
23 c.Header("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
24 }
25
26 // 预检请求直接返回
27 if c.Request.Method == http.MethodOptions {
28 c.AbortWithStatus(http.StatusNoContent)
29 return
30 }
31 c.Next()
32 })
33 // =======================================
34
35 // CodeShare 分组
36 svc := service.NewCodeShareService()
37 codeHandler := NewCodeShareHandler(svc)
38 cg := r.Group("/codeshare")
39 {
40 cg.POST("/upload", codeHandler.Upload)
41 cg.GET("/code/:hash", codeHandler.Get)
42 }
43
44 // WorkPlan 分组
45 workPlanService := service.NewWorkPlan()
46 workPlanHandler := NewWorkPlanHandler(workPlanService)
47 wg := r.Group("/workplan")
48 {
49 wg.GET("/new", workPlanHandler.NewPersonlPlan)
50 wg.POST("/add", workPlanHandler.AddTODO)
51 wg.POST("/delete", workPlanHandler.DeleteTODO)
52 wg.POST("/edit", workPlanHandler.EditTODO)
53 wg.POST("/done", workPlanHandler.SetDone)
54 wg.GET("/:hash", workPlanHandler.GetTODOs)
55 }
56
57 // Markdown 分组
58 mdService := service.NewMarkdown()
59 mdHandler := NewMarkdownHandler(mdService)
60 mg := r.Group("/markdown")
61 {
62 mg.GET("/new", mdHandler.NewDocument)
63 mg.GET("/:hash", mdHandler.GetDocument)
64 mg.POST("/update", mdHandler.UpdateDocument)
65 mg.GET("/stream/:hash", mdHandler.StreamDocument)
66 }
67
68 // HttpTest 分组

Callers

nothing calls this directly

Calls 7

BaseDirMethod · 0.95
NewCodeShareHandlerFunction · 0.85
NewWorkPlanHandlerFunction · 0.85
NewMarkdownHandlerFunction · 0.85
NewHttpTestHandlerFunction · 0.85
NewHtmlHostHandlerFunction · 0.85
GetMethod · 0.45

Tested by

no test coverage detected