From ff730652ed261c37ae263fe60199f335221167a7 Mon Sep 17 00:00:00 2001 From: yyamada12 <12yacropolisy@gmail.com> Date: Sat, 25 Nov 2023 06:55:28 +0000 Subject: [PATCH] add initialize handler for pdns and add index to records --- webapp/go/main.go | 20 ++++++++++++++++++++ webapp/pdns/add-index.sql | 1 + 2 files changed, 21 insertions(+) create mode 100644 webapp/pdns/add-index.sql diff --git a/webapp/go/main.go b/webapp/go/main.go index d04e6cd..fdb51e2 100644 --- a/webapp/go/main.go +++ b/webapp/go/main.go @@ -282,6 +282,25 @@ func initializeHandler(c echo.Context) error { }) } +func initializeDNSHandler(c echo.Context) error { + if out, err := exec.Command("../pdns/init_zone.sh").CombinedOutput(); err != nil { + c.Logger().Warnf("init_zone.sh failed with err=%s", string(out)) + return echo.NewHTTPError(http.StatusInternalServerError, "failed to initialize: "+err.Error()) + } + + // if err := os.RemoveAll("/home/isucon/webapp/icon/"); err != nil { + // return echo.NewHTTPError(http.StatusInternalServerError, "failed to remove directory: "+err.Error()) + // } + // if err := os.Mkdir("/home/isucon/webapp/icon/", 0755); err != nil { + // return echo.NewHTTPError(http.StatusInternalServerError, "failed to create directory: "+err.Error()) + // } + + c.Request().Header.Add("Content-Type", "application/json;charset=utf-8") + return c.JSON(http.StatusOK, InitializeResponse{ + Language: "golang", + }) +} + func main() { go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) @@ -298,6 +317,7 @@ func main() { // 初期化 e.POST("/api/initialize", initializeHandler) + e.POST("/api/initialize_dns", initializeDNSHandler) // top e.GET("/api/tag", getTagHandler) diff --git a/webapp/pdns/add-index.sql b/webapp/pdns/add-index.sql new file mode 100644 index 0000000..84b2095 --- /dev/null +++ b/webapp/pdns/add-index.sql @@ -0,0 +1 @@ +CREATE INDEX idx_records_name_type ON records(name, type);