From ecdc3b235cce8911e2eff135a6880ab80eca1e45 Mon Sep 17 00:00:00 2001 From: qowevisa Date: Tue, 6 Aug 2024 22:51:34 +0300 Subject: [PATCH] Add ping --- cmd/http-server/main.go | 10 ++++------ handlers/ping.go | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 handlers/ping.go diff --git a/cmd/http-server/main.go b/cmd/http-server/main.go index b17231a..d2b3b5c 100644 --- a/cmd/http-server/main.go +++ b/cmd/http-server/main.go @@ -32,20 +32,18 @@ func main() { r := gin.Default() docs.SwaggerInfo.BasePath = "/api" r.Use(cors.New(cors.Config{ - AllowOrigins: []string{"http://localhost:3001"}, - AllowMethods: []string{"GET", "DELETE", "PUT", "PATCH"}, + AllowOrigins: []string{"*"}, + AllowMethods: []string{"GET", "DELETE", "PUT", "PATCH", "OPTIONS"}, AllowHeaders: []string{"Origin"}, ExposeHeaders: []string{"Content-Length"}, AllowCredentials: true, - AllowOriginFunc: func(origin string) bool { - return origin == "https://github.com" - }, - MaxAge: 12 * time.Hour, + MaxAge: 12 * time.Hour, })) // Routes defined in the routes package api := r.Group("/api") { + api.GET("/ping", handlers.PingGet) userRoutes := api.Group("/user") { userRoutes.POST("/register", handlers.UserRegister) diff --git a/handlers/ping.go b/handlers/ping.go new file mode 100644 index 0000000..94fd457 --- /dev/null +++ b/handlers/ping.go @@ -0,0 +1,17 @@ +package handlers + +import ( + "git.qowevisa.me/Qowevisa/gonuts/types" + "github.com/gin-gonic/gin" +) + +// @Summary Ping +// @Description Pong +// @Tags user +// @Accept json +// @Produce json +// @Success 200 {object} types.Message +// @Router /ping [get] +func PingGet(c *gin.Context) { + c.JSON(200, types.Message{Message: "Pong!"}) +}