mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-18 07:13:50 +01:00
- These changes makes the API incombatible with previous versions - Added new types for error handling, success responses, and health checks. - Updated health check logic to utilize the new types for better clarity and structure. - Refactored existing handlers to improve response consistency and error handling. - Updated Makefile to include a new target for generating API types from Swagger. - Updated "new agent" API to respond an encrypted cert pair
47 lines
1.3 KiB
Go
47 lines
1.3 KiB
Go
package homepageapi
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
apitypes "github.com/yusing/go-proxy/internal/api/types"
|
|
"github.com/yusing/go-proxy/internal/route/routes"
|
|
)
|
|
|
|
type HomepageItemsRequest struct {
|
|
Category string `form:"category" validate:"omitempty"`
|
|
Provider string `form:"provider" validate:"omitempty"`
|
|
} // @name HomepageItemsRequest
|
|
|
|
// @x-id "items"
|
|
// @BasePath /api/v1
|
|
// @Summary Homepage items
|
|
// @Description Homepage items
|
|
// @Tags homepage
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param category query string false "Category filter"
|
|
// @Param provider query string false "Provider filter"
|
|
// @Success 200 {object} homepage.Homepage
|
|
// @Failure 400 {object} apitypes.ErrorResponse
|
|
// @Failure 403 {object} apitypes.ErrorResponse
|
|
// @Router /homepage/items [get]
|
|
func Items(c *gin.Context) {
|
|
var request HomepageItemsRequest
|
|
if err := c.ShouldBindQuery(&request); err != nil {
|
|
c.JSON(http.StatusBadRequest, apitypes.Error("invalid request", err))
|
|
return
|
|
}
|
|
|
|
proto := "http"
|
|
if c.Request.TLS != nil || c.GetHeader("X-Forwarded-Proto") == "https" {
|
|
proto = "https"
|
|
}
|
|
hostname := c.Request.Host
|
|
if host := c.GetHeader("X-Forwarded-Host"); host != "" {
|
|
hostname = host
|
|
}
|
|
|
|
c.JSON(http.StatusOK, routes.HomepageItems(proto, hostname, request.Category, request.Provider))
|
|
}
|