mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-11 22:30:47 +01:00
Split the monolithic `internal/homepage` icons functionality into a structured package hierarchy: - `internal/homepage/icons/` - Core types (URL, Key, Meta, Provider, Source, Variant) - `internal/homepage/icons/fetch/` - Icon fetching logic (content.go, fetch.go, route.go) - `internal/homepage/icons/list/` - Icon listing and search (list_icons.go, list_icons_test.go) Moved icon-related code from `internal/homepage/`: - `icon_url.go` → `icons/url.go` (+ url_test.go) - `content.go` → `icons/fetch/content.go` - `route.go` → `icons/fetch/route.go` - `list_icons.go` → `icons/list/list_icons.go` (+ list_icons_test.go) Updated all consumers to use the new package structure: - `cmd/main.go` - `internal/api/v1/favicon.go` - `internal/api/v1/icons.go` - `internal/idlewatcher/handle_http.go` - `internal/route/route.go`
38 lines
1.0 KiB
Go
38 lines
1.0 KiB
Go
package v1
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
iconlist "github.com/yusing/godoxy/internal/homepage/icons/list"
|
|
apitypes "github.com/yusing/goutils/apitypes"
|
|
)
|
|
|
|
type ListIconsRequest struct {
|
|
Limit int `form:"limit" validate:"omitempty,min=0"`
|
|
Keyword string `form:"keyword" validate:"required"`
|
|
} // @name ListIconsRequest
|
|
|
|
// @x-id "icons"
|
|
// @BasePath /api/v1
|
|
// @Summary List icons
|
|
// @Description List icons
|
|
// @Tags v1
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param limit query int false "Limit"
|
|
// @Param keyword query string false "Keyword"
|
|
// @Success 200 {array} homepage.IconMetaSearch
|
|
// @Failure 400 {object} apitypes.ErrorResponse
|
|
// @Failure 403 {object} apitypes.ErrorResponse
|
|
// @Router /icons [get]
|
|
func Icons(c *gin.Context) {
|
|
var request ListIconsRequest
|
|
if err := c.ShouldBindQuery(&request); err != nil {
|
|
c.JSON(http.StatusBadRequest, apitypes.Error("invalid request", err))
|
|
return
|
|
}
|
|
icons := iconlist.SearchIcons(request.Keyword, request.Limit)
|
|
c.JSON(http.StatusOK, icons)
|
|
}
|