go for it

This commit is contained in:
Sebastian Cabrera 2025-06-11 14:44:52 -04:00
parent 3767be9f67
commit c107d94b11
Signed by: okseby
GPG key ID: DA858232740D0404
5 changed files with 137 additions and 1 deletions

33
server/server.go Normal file
View file

@ -0,0 +1,33 @@
package server
import (
"fmt"
"net"
)
type Server struct {
addr string
}
func NewServer(addr string) *Server {
return &Server{addr: addr}
}
func (s *Server) ListenAndServe() {
listener, err := net.Listen("tcp", s.addr)
if err != nil {
fmt.Println("Error binding to address:", err)
}
defer listener.Close()
fmt.Printf("Server listening on %s\n", s.addr)
for {
conn, err := listener.Accept()
if err != nil {
fmt.Println("Error accepting connection:", err)
continue
}
go handleConnection(conn)
}
}