MCPcopy Create free account
hub / github.com/aurora-develop/Duck2api / RegisterRouter

Function RegisterRouter

initialize/router.go:10–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

8)
9
10func RegisterRouter() *gin.Engine {
11 handler := NewHandle(
12 checkProxy(),
13 )
14
15 router := gin.Default()
16 router.Use(middlewares.Cors)
17
18 router.GET("/", func(c *gin.Context) {
19 c.JSON(200, gin.H{
20 "message": "Hello, world!",
21 })
22 })
23
24 router.GET("/ping", func(c *gin.Context) {
25 c.JSON(200, gin.H{
26 "message": "pong",
27 })
28 })
29
30 prefixGroup := os.Getenv("PREFIX")
31 if prefixGroup != "" {
32 prefixRouter := router.Group(prefixGroup)
33 {
34 prefixRouter.OPTIONS("/v1/chat/completions", optionsHandler)
35 prefixRouter.OPTIONS("/v1/chat/models", optionsHandler)
36 prefixRouter.OPTIONS("/v1/responses", optionsHandler)
37 prefixRouter.OPTIONS("/v1/response", optionsHandler)
38 prefixRouter.POST("/v1/chat/completions", middlewares.Authorization, handler.duckduckgo)
39 prefixRouter.POST("/v1/responses", middlewares.Authorization, handler.responses)
40 prefixRouter.POST("/v1/response", middlewares.Authorization, handler.responses)
41 prefixRouter.GET("/v1/models", middlewares.Authorization, handler.engines)
42 }
43 }
44
45 router.OPTIONS("/v1/chat/completions", optionsHandler)
46 router.OPTIONS("/v1/chat/models", optionsHandler)
47 router.OPTIONS("/v1/responses", optionsHandler)
48 router.OPTIONS("/v1/response", optionsHandler)
49 authGroup := router.Group("").Use(middlewares.Authorization)
50 authGroup.POST("/v1/chat/completions", handler.duckduckgo)
51 authGroup.POST("/v1/responses", handler.responses)
52 authGroup.POST("/v1/response", handler.responses)
53 authGroup.GET("/v1/models", handler.engines)
54 return router
55}

Callers 2

mainFunction · 0.92
initFunction · 0.92

Calls 2

NewHandleFunction · 0.85
checkProxyFunction · 0.85

Tested by

no test coverage detected