[PD2] Gateway started

This commit is contained in:
Afonso Franco 2024-05-29 17:33:36 +01:00
parent 49a29e43a7
commit aa90bfddce
Signed by: afonso
SSH key fingerprint: SHA256:PQTRDHPH3yALEGtHXnXBp3Orfcn21pK20t0tS1kHg54
3 changed files with 80 additions and 2 deletions

View file

@ -1,5 +1,77 @@
package gateway
func Run(){
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")
}
func Run(){
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(),
}
err = server.ListenAndServeTLS("", "")
if err!=nil {
log.Fatal(err.Error())
}
}

View file

@ -52,6 +52,11 @@ type (
Timestamp time.Time `json:"timestamp"`
}
PostRegister struct {
Password string `json:"password"`
Certificate []byte `json:"certificate"`
}
ReportError struct {
ErrorMessage string `json:"error"`
}

View file

@ -141,7 +141,8 @@ func Run() {
server := http.Server{
Addr: "0.0.0.0:8080",
Handler: r,
TLSConfig: serverKeyStore.GetTLSConfig(),
//TODO: Verify if it's the gateway
TLSConfig: serverKeyStore.GetServerTLSConfig(),
}
err = server.ListenAndServeTLS("", "")