szoe-pontok/api/endpotins.go

41 lines
704 B
Go
Raw Normal View History

2024-10-10 18:22:03 +00:00
package api
import (
"net/http"
"time"
"git.tek.govt.hu/dowerx/szoe-pontok/api/auth"
"github.com/gin-gonic/gin"
)
func Listen(address string, path string) {
router := gin.Default()
api := router.Group(path)
{
api.GET("/ping", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"message": "pong",
"date": time.Now().UTC().Unix(),
})
})
apiAuth := api.Group("auth")
{
apiAuth.POST("register", auth.Register)
apiAuth.GET("login", auth.Login)
}
}
server := &http.Server{
Addr: address,
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
if err := server.ListenAndServe(); err != nil {
panic(err)
}
}