mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-24 01:51:10 +01:00
34 lines
914 B
Go
34 lines
914 B
Go
package routeApi
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
config "github.com/yusing/godoxy/internal/config/types"
|
|
"github.com/yusing/godoxy/internal/net/gphttp/websocket"
|
|
"github.com/yusing/goutils/http/httpheaders"
|
|
)
|
|
|
|
// @x-id "providers"
|
|
// @BasePath /api/v1
|
|
// @Summary List route providers
|
|
// @Description List route providers
|
|
// @Tags route,websocket
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {array} config.RouteProviderListResponse
|
|
// @Failure 403 {object} apitypes.ErrorResponse
|
|
// @Failure 500 {object} apitypes.ErrorResponse
|
|
// @Router /route/providers [get]
|
|
func Providers(c *gin.Context) {
|
|
cfg := config.GetInstance()
|
|
if httpheaders.IsWebsocket(c.Request.Header) {
|
|
websocket.PeriodicWrite(c, 5*time.Second, func() (any, error) {
|
|
return config.GetInstance().RouteProviderList(), nil
|
|
})
|
|
} else {
|
|
c.JSON(http.StatusOK, cfg.RouteProviderList())
|
|
}
|
|
}
|