Showing
3 changed files
with
38 additions
and
0 deletions
bunjang/controller/controller.go
0 → 100644
1 | +package controller | ||
2 | + | ||
3 | +import ( | ||
4 | + "bunjang/service" | ||
5 | + "net/http" | ||
6 | + | ||
7 | + "github.com/labstack/echo/v4" | ||
8 | +) | ||
9 | + | ||
10 | +func Search(c echo.Context) error { | ||
11 | + keyword := c.Param("keyword") | ||
12 | + items, err := service.GetItemByKeyword(keyword) | ||
13 | + if err != nil { | ||
14 | + return err | ||
15 | + } | ||
16 | + return c.JSON(http.StatusOK, items) | ||
17 | +} |
1 | package main | 1 | package main |
2 | 2 | ||
3 | import ( | 3 | import ( |
4 | + "bunjang/router" | ||
5 | + | ||
4 | "github.com/labstack/echo/v4" | 6 | "github.com/labstack/echo/v4" |
5 | ) | 7 | ) |
6 | 8 | ||
7 | func main() { | 9 | func main() { |
8 | e := echo.New() | 10 | e := echo.New() |
9 | 11 | ||
12 | + router.Init(e) | ||
13 | + | ||
10 | e.Logger.Fatal(e.Start(":8080")) | 14 | e.Logger.Fatal(e.Start(":8080")) |
11 | } | 15 | } | ... | ... |
bunjang/router/router.go
0 → 100644
1 | +package router | ||
2 | + | ||
3 | +import ( | ||
4 | + "bunjang/controller" | ||
5 | + | ||
6 | + "github.com/labstack/echo/v4" | ||
7 | +) | ||
8 | + | ||
9 | +const ( | ||
10 | + API = "/api/v2" | ||
11 | + APIBunJang = API + "/bunjang" | ||
12 | + APIKeyword = APIBunJang + "/:keyword" | ||
13 | +) | ||
14 | + | ||
15 | +func Init(e *echo.Echo) { | ||
16 | + e.GET(APIKeyword, controller.Search) | ||
17 | +} |
-
Please register or login to post a comment