Spaces:
Paused
Paused
Download bin/modules/chapter/handlers/http_handler.go from citedd/komiku-api: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/spaces/citedd/komiku-api/resolve/main/bin/modules/chapter/handlers/http_handler.go
- Command line
-
hf download hf://spaces/citedd/komiku-api/bin/modules/chapter/handlers/http_handler.go
-
curl -L -o http_handler.go https://huggingface.co/spaces/citedd/komiku-api/resolve/main/bin/modules/chapter/handlers/http_handler.go
1.09 kB
| package handlers | |
| import ( | |
| "github.com/gocolly/colly" | |
| "github.com/labstack/echo/v4" | |
| "komikku-api/bin/config" | |
| chapterQ "komikku-api/bin/modules/chapter/repositories/queries" | |
| chapterU "komikku-api/bin/modules/chapter/usecases" | |
| "komikku-api/bin/pkg/utils" | |
| "net/http" | |
| ) | |
| type ChapterHandler struct { | |
| chapterCommandUsecase chapterU.ChapterUsecase | |
| } | |
| func New() *ChapterHandler { | |
| collector := colly.NewCollector() | |
| queryChapter := chapterQ.NewChapterQuery(config.GlobalEnv.BaseURL, collector) | |
| queryUsecase := chapterU.CreateNewChapterUsecase(queryChapter) | |
| return &ChapterHandler{ | |
| chapterCommandUsecase: queryUsecase, | |
| } | |
| } | |
| func (c *ChapterHandler) Mount(router *echo.Echo) { | |
| api := router.Group("/api") | |
| api.GET("/comic/chapter/:endpoint", c.GetChapterDetail) | |
| } | |
| func(m *ChapterHandler) GetChapterDetail(c echo.Context) error { | |
| endpoint := c.Param("endpoint") | |
| result := m.chapterCommandUsecase.GetChapterDetail(endpoint) | |
| if result.Error != nil { | |
| return utils.ResponseError(result.Error, c) | |
| } | |
| return utils.Response(result.Data, "Get Chapter Detail", http.StatusOK, c) | |
| } | |