MCPcopy
hub / github.com/yusing/godoxy / newAPIHandler

Function newAPIHandler

cmd/debug_page.go:161–264  ·  view source on GitHub ↗
(debugMux *debugMux)

Source from the content-addressed store, hash-verified

159}
160
161func newAPIHandler(debugMux *debugMux) *gin.Engine {
162 r := gin.New()
163 r.Use(api.ErrorHandler())
164 r.Use(api.ErrorLoggingMiddleware())
165 r.Use(api.NoCache())
166
167 registerGinRoute := func(router gin.IRouter, method, name string, path string, handler gin.HandlerFunc) {
168 if group, ok := router.(*gin.RouterGroup); ok {
169 debugMux.registerEndpoint(name, method, group.BasePath()+path)
170 } else {
171 debugMux.registerEndpoint(name, method, path)
172 }
173 router.Handle(method, path, handler)
174 }
175
176 registerGinRoute(r, "GET", "App version", "/api/v1/version", apiV1.Version)
177
178 v1 := r.Group("/api/v1")
179 if auth.IsEnabled() {
180 v1Auth := v1.Group("/auth")
181 {
182 registerGinRoute(v1Auth, "HEAD", "Auth check", "/check", authApi.Check)
183 registerGinRoute(v1Auth, "POST", "Auth login", "/login", authApi.Login)
184 registerGinRoute(v1Auth, "GET", "Auth callback", "/callback", authApi.Callback)
185 registerGinRoute(v1Auth, "POST", "Auth callback", "/callback", authApi.Callback)
186 registerGinRoute(v1Auth, "POST", "Auth logout", "/logout", authApi.Logout)
187 registerGinRoute(v1Auth, "GET", "Auth logout", "/logout", authApi.Logout)
188 }
189 }
190
191 {
192 // enable cache for favicon
193 registerGinRoute(v1, "GET", "Route favicon", "/favicon", apiV1.FavIcon)
194 registerGinRoute(v1, "GET", "Route health", "/health", apiV1.Health)
195 registerGinRoute(v1, "GET", "List icons", "/icons", apiV1.Icons)
196 registerGinRoute(v1, "GET", "Route stats", "/stats", apiV1.Stats)
197
198 route := v1.Group("/route")
199 {
200 registerGinRoute(route, "GET", "List routes", "/list", routeApi.Routes)
201 registerGinRoute(route, "GET", "Get route", "/:which", routeApi.Route)
202 registerGinRoute(route, "GET", "List providers", "/providers", routeApi.Providers)
203 registerGinRoute(route, "GET", "List routes by provider", "/by_provider", routeApi.ByProvider)
204 registerGinRoute(route, "POST", "Playground", "/playground", routeApi.Playground)
205 }
206
207 file := v1.Group("/file")
208 {
209 registerGinRoute(file, "GET", "List files", "/list", fileApi.List)
210 registerGinRoute(file, "GET", "Get file", "/content", fileApi.Get)
211 registerGinRoute(file, "PUT", "Set file", "/content", fileApi.Set)
212 registerGinRoute(file, "POST", "Set file", "/content", fileApi.Set)
213 registerGinRoute(file, "POST", "Validate file", "/validate", fileApi.Validate)
214 }
215
216 homepage := v1.Group("/homepage")
217 {
218 registerGinRoute(homepage, "GET", "List categories", "/categories", homepageApi.Categories)

Callers 1

listenDebugServerFunction · 0.85

Calls 7

ErrorHandlerFunction · 0.92
ErrorLoggingMiddlewareFunction · 0.92
NoCacheFunction · 0.92
IsEnabledFunction · 0.92
NewMethod · 0.80
registerEndpointMethod · 0.80
HandleMethod · 0.45

Tested by

no test coverage detected