2024-05-28 20:08:25 +01:00
|
|
|
package gateway
|
|
|
|
|
2024-05-29 17:33:36 +01:00
|
|
|
import (
|
|
|
|
"PD1/internal/protocol"
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func HandleGetMessage(c *gin.Context){
|
|
|
|
fmt.Println("Get Message Handler")
|
|
|
|
|
|
|
|
}
|
|
|
|
func HandleGetUnreadMsgsInfo(c *gin.Context){
|
|
|
|
fmt.Println("Get Unread Messages Info Handler")
|
|
|
|
|
|
|
|
}
|
|
|
|
func HandleGetUserCert(c *gin.Context){
|
|
|
|
fmt.Println("Get User Cert Handler")
|
|
|
|
|
|
|
|
}
|
|
|
|
func HandleSendMessage(c *gin.Context){
|
|
|
|
fmt.Println("Send Message Handler")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func HandleRegister(c *gin.Context){
|
|
|
|
var postRegister protocol.PostRegister
|
|
|
|
c.Bind(postRegister)
|
|
|
|
//Hash the password (using salt) and store it on the db
|
|
|
|
//Get the username from the certificate
|
|
|
|
}
|
|
|
|
|
|
|
|
func AuthMiddleware(c *gin.Context){
|
|
|
|
fmt.Println("Authentication Middleware")
|
|
|
|
}
|
|
|
|
|
2024-05-28 20:08:25 +01:00
|
|
|
func Run(){
|
2024-05-29 17:33:36 +01:00
|
|
|
router := gin.Default()
|
|
|
|
|
|
|
|
auth := router.Group("/", func(c *gin.Context) {
|
|
|
|
AuthMiddleware(c)
|
|
|
|
})
|
|
|
|
|
|
|
|
auth.GET("/message/:num", func(c *gin.Context) {
|
|
|
|
HandleGetMessage(c)
|
|
|
|
})
|
|
|
|
|
|
|
|
auth.GET("/queue", func(c *gin.Context) {
|
|
|
|
HandleGetUnreadMsgsInfo(c)
|
|
|
|
})
|
|
|
|
|
|
|
|
auth.GET("/cert/:user", func(c *gin.Context) {
|
|
|
|
HandleGetUserCert(c)
|
|
|
|
})
|
|
|
|
|
|
|
|
auth.POST("/message", func(c *gin.Context) {
|
|
|
|
HandleSendMessage(c)
|
|
|
|
})
|
|
|
|
|
|
|
|
router.POST("/register",func(c *gin.Context) {
|
|
|
|
HandleRegister(c)
|
|
|
|
})
|
|
|
|
|
|
|
|
server := http.Server{
|
|
|
|
Addr: "0.0.0.0:8080",
|
|
|
|
Handler: router,
|
|
|
|
//TODO: Verify if it's the gateway
|
|
|
|
TLSConfig: serverKeyStore.GetServerTLSConfig(),
|
|
|
|
}
|
2024-05-28 20:08:25 +01:00
|
|
|
|
2024-05-29 17:33:36 +01:00
|
|
|
err = server.ListenAndServeTLS("", "")
|
|
|
|
if err!=nil {
|
|
|
|
log.Fatal(err.Error())
|
|
|
|
}
|
2024-05-28 20:08:25 +01:00
|
|
|
}
|