This commit is contained in:
qowevisa 2024-08-06 22:51:34 +03:00
parent d5c898520d
commit ecdc3b235c
2 changed files with 21 additions and 6 deletions

View File

@ -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)

17
handlers/ping.go Normal file
View File

@ -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!"})
}