new quic release [chat tests] 6
All checks were successful
Create and publish a Docker image 🚀 / build-and-push-image (push) Successful in 1m29s

This commit is contained in:
Smile Rex
2026-03-10 01:09:59 +03:00
parent 999d4b2238
commit d56b51065f

18
main.go
View File

@@ -6,6 +6,7 @@ import (
"log"
"net/http"
"github.com/quic-go/quic-go/http3"
"github.com/quic-go/webtransport-go"
)
@@ -13,13 +14,13 @@ func main() {
mux := http.NewServeMux()
wm := &webtransport.Server{
wt := &webtransport.Server{
CheckOrigin: func(r *http.Request) bool { return true },
}
mux.HandleFunc("/chat", func(w http.ResponseWriter, r *http.Request) {
session, err := wm.Upgrade(w, r)
session, err := wt.Upgrade(w, r)
if err != nil {
log.Println("upgrade error:", err)
return
@@ -28,12 +29,12 @@ func main() {
go handleChatSession(session)
})
server := &http.Server{
server := http3.Server{
Addr: ":8080",
Handler: mux,
}
fmt.Println("Server started")
fmt.Println("HTTP/3 server started")
log.Fatal(server.ListenAndServe())
}
@@ -41,25 +42,20 @@ func main() {
func handleChatSession(session *webtransport.Session) {
for {
stream, err := session.AcceptStream(context.Background())
if err != nil {
return
}
go func(s *webtransport.Stream) {
go func(s webtransport.Stream) {
defer s.Close()
buf := make([]byte, 1024)
n, _ := s.Read(buf)
fmt.Println("Message:", string(buf[:n]))
s.Write([]byte("Server: OK"))
}(stream)
}(*stream)
}
}