chore: initialise backend
This won't be touched until a basic player prototype is implemented. The backend itself is implemented in Go.
This commit is contained in:
parent
a8ddd3d740
commit
5ad18b9027
3
backend/go.mod
Normal file
3
backend/go.mod
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module github.com/devraza/ambition/backend
|
||||||
|
|
||||||
|
go 1.20
|
38
backend/main.go
Normal file
38
backend/main.go
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net"
|
||||||
|
"os"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
serverAddress = "localhost:7764"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
log.Println("Ambition going strong at", serverAddress)
|
||||||
|
|
||||||
|
listener, err := net.Listen("tcp", serverAddress)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalln("Failed to initialise TCP listener", err)
|
||||||
|
}
|
||||||
|
defer listener.close()
|
||||||
|
|
||||||
|
for {
|
||||||
|
conn, err := listener.Accept()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Failed to accept connection:", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Concurrency FTW
|
||||||
|
go handleConnection(conn)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func handleConnection(conn net.Conn) {
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
// TODO implement actual server. Waiting on frontend for this
|
||||||
|
}
|
Reference in a new issue