package server import ( "PD1/internal/protocol" "PD1/internal/utils/networking" "fmt" ) func clientHandler(connection networking.Connection[protocol.Packet], dataStore DataStore) { defer connection.Conn.Close() // FIX: GET THE UID FROM THE USER CERTIFICATE FROM THE TLS SESSION uid := "0" for { pac := connection.Receive() switch pac.Flag { case protocol.ReqUserCertPkt: userCertPacket := dataStore.GetUserCertificate(uid) connection.Send(userCertPacket) case protocol.ReqAllMsgPkt: fmt.Println("ReqAllMsg") case protocol.ReqMsgPkt: fmt.Println("ReqMsg") case protocol.SubmitMsgPkt: fmt.Println("SubmitMsg") } } } func Run(port int) { //Open connection to DB dataStore := OpenDB() defer dataStore.db.Close() //Create server listener server := networking.NewServer[protocol.Packet](port) go server.ListenLoop() for { //Receive Connection via channel conn := <-server.C //Launch client handler via clientHandler go clientHandler(conn, dataStore) } }