server/api/endpoints.go
2025-06-04 19:14:58 +02:00

34 lines
609 B
Go

package api
import (
"net/http"
"time"
"github.com/gin-gonic/gin"
)
func Listen(address string, base string) error {
router := gin.Default()
api := router.Group(base)
auth := api.Group("auth")
auth.POST("register", register)
auth.POST("login", login)
auth.GET("logout", isLoggedIn, logout)
auth.GET("bump", isLoggedIn, bump)
user := api.Group("user")
user.Use(isLoggedIn)
user.GET("info/:username", userInfo)
server := &http.Server{
Addr: address,
Handler: router,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
return server.ListenAndServe()
}