mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-19 15:31:37 +02:00
fix: add nil guard before entrypoint retrieval; move config from types/
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/yusing/godoxy/internal/route"
|
||||
|
||||
_ "github.com/yusing/goutils/apitypes"
|
||||
apitypes "github.com/yusing/goutils/apitypes"
|
||||
)
|
||||
|
||||
type RoutesByProvider map[string][]route.Route
|
||||
@@ -25,5 +26,9 @@ type RoutesByProvider map[string][]route.Route
|
||||
// @Router /route/by_provider [get]
|
||||
func ByProvider(c *gin.Context) {
|
||||
ep := entrypoint.FromCtx(c.Request.Context())
|
||||
if ep == nil { // impossible, but just in case
|
||||
c.JSON(http.StatusInternalServerError, apitypes.Error("entrypoint not initialized"))
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, ep.RoutesByProvider())
|
||||
}
|
||||
|
||||
@@ -33,6 +33,11 @@ func Route(c *gin.Context) {
|
||||
}
|
||||
|
||||
ep := entrypoint.FromCtx(c.Request.Context())
|
||||
if ep == nil { // impossible, but just in case
|
||||
c.JSON(http.StatusInternalServerError, apitypes.Error("entrypoint not initialized"))
|
||||
return
|
||||
}
|
||||
|
||||
route, ok := ep.GetRoute(request.Which)
|
||||
if ok {
|
||||
c.JSON(http.StatusOK, route)
|
||||
|
||||
Reference in New Issue
Block a user