[PD2] Gateway started
This commit is contained in:
parent
49a29e43a7
commit
aa90bfddce
3 changed files with 80 additions and 2 deletions
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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("", "")
|
||||
|
|
Loading…
Reference in a new issue