Skip to content

Commit

Permalink
main.go を配信できるように変更
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaki256 committed Nov 21, 2023
1 parent e9c1cf4 commit 982ba49
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
@@ -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())
Expand All @@ -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)
}

0 comments on commit 982ba49

Please sign in to comment.