From 982ba49d639befa0aa2cad45f2f3b0c21a56c349 Mon Sep 17 00:00:00 2001 From: Pina641 Date: Tue, 21 Nov 2023 19:21:03 +0900 Subject: [PATCH] =?UTF-8?q?main.go=20=E3=82=92=E9=85=8D=E4=BF=A1=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index d0dde6c..1605c34 100644 --- a/main.go +++ b/main.go @@ -1,22 +1,37 @@ package main import ( - "go-backend-template/internal/handler" - "go-backend-template/internal/migration" - "go-backend-template/internal/pkg/config" - "go-backend-template/internal/repository" + "fmt" + + "github.com/Kaki256/multiple-word-search-backend/internal/handler" + "github.com/Kaki256/multiple-word-search-backend/internal/migration" + "github.com/Kaki256/multiple-word-search-backend/internal/pkg/config" + "github.com/Kaki256/multiple-word-search-backend/internal/repository" "github.com/jmoiron/sqlx" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" + + "net/http" ) +type Word struct { + Name string `json:"name"` +} + +type Dictionary struct { + Words []Word `json:"words"` +} + func main() { e := echo.New() // middlewares e.Use(middleware.Recover()) e.Use(middleware.Logger()) + e.Use(middleware.CORS()) + + e.POST("/api/dictionary", postDictionaryHandler) // connect to database db, err := sqlx.Connect("mysql", config.MySQL().FormatDSN()) @@ -40,3 +55,13 @@ func main() { e.Logger.Fatal(e.Start(config.AppAddr())) } + +func postDictionaryHandler(c echo.Context) error { + dict := &Dictionary{} + err := c.Bind(dict) + + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("%+v", err)) + } + return c.JSON(http.StatusOK, dict) +}