-
-
Notifications
You must be signed in to change notification settings - Fork 72
Added an example for webtransport-go
#220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
kavin81
commented
Dec 30, 2025
- this PR is for add an example #154
- it's a simple hello-world example where if client sends "hello" -> server responds with "World!"
- also just fixed a misc typo in comments
Add a runnable helloWorld example with a WebTransport server on
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a hello world example for the webtransport-go library and fixes a documentation URL in server.go. The example demonstrates basic bidirectional communication where a client can send messages to a server via WebTransport streams, with the server responding "world!" to "hello" messages.
- Adds a complete hello world example with client, server, and shared configuration code
- Includes comprehensive documentation with usage instructions and mermaid flowcharts
- Updates the server.go comment to use a more specific URL format
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| server.go | Updates documentation URL to use a more specific anchor link format |
| examples/go.mod | Defines the Go module for examples with dependencies |
| examples/go.sum | Contains checksums for example dependencies |
| examples/README.md | Provides overview of available examples |
| examples/helloWorld/README.md | Comprehensive documentation for the hello world example |
| examples/helloWorld/common/config.go | Shared configuration including TLS setup and server settings |
| examples/helloWorld/server/main.go | WebTransport server implementation |
| examples/helloWorld/client/main.go | Interactive WebTransport client implementation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
examples/helloWorld/README.md
Outdated
| Server response: world! | ||
|
|
||
| Enter message: test | ||
| Server response: echo: test |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example output on line 42 shows "Server response: echo: test", but the actual server implementation (server/main.go line 75) sends "I only respond to 'hello' with 'world!'" for any non-"hello" message. The example output should match the actual server behavior.
examples/helloWorld/common/config.go
Outdated
| SerialNumber: big.NewInt(1), | ||
| NotBefore: time.Now(), | ||
| NotAfter: time.Now().Add(365 * 24 * time.Hour), | ||
| DNSNames: []string{"localhost"}, |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The self-signed certificate lacks required basic fields for x509.Certificate. The certificate should include KeyUsage and ExtKeyUsage fields to properly identify its purpose. Additionally, consider adding IsCA: false to explicitly indicate this is not a CA certificate.
| SerialNumber: big.NewInt(1), | |
| NotBefore: time.Now(), | |
| NotAfter: time.Now().Add(365 * 24 * time.Hour), | |
| DNSNames: []string{"localhost"}, | |
| SerialNumber: big.NewInt(1), | |
| NotBefore: time.Now(), | |
| NotAfter: time.Now().Add(365 * 24 * time.Hour), | |
| DNSNames: []string{"localhost"}, | |
| KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment, | |
| ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, | |
| IsCA: false, | |
| BasicConstraintsValid: true, |
examples/helloWorld/server/main.go
Outdated
| func handleStream(stream *webtransport.Stream) { | ||
| defer stream.Close() | ||
|
|
||
| data, err := io.ReadAll(stream) |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using io.ReadAll on an incoming stream without any size limit or timeout can lead to resource exhaustion if a malicious client sends a very large message. Consider implementing a maximum message size limit or using io.LimitReader to protect against DoS attacks.
examples/helloWorld/server/main.go
Outdated
| @@ -0,0 +1,86 @@ | |||
| package server | |||
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package declaration should be "main" instead of "server" for an executable program. Go programs that should be run with "go run" must be in package main with a main() function.
| package server | |
| package main |
examples/helloWorld/client/main.go
Outdated
| @@ -0,0 +1,96 @@ | |||
| package client | |||
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The package declaration should be "main" instead of "client" for an executable program. Go programs that should be run with "go run" must be in package main with a main() function.
| package client | |
| package main |
examples/helloWorld/README.md
Outdated
| B --> C[Connected!] | ||
| C --> D[Get User Input] | ||
| D --> E{quit?} | ||
| E -->|Yes| F[lose & Exit] |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in the flowchart. "lose" should be "Close" to properly indicate "Close & Exit".
| E -->|Yes| F[lose & Exit] | |
| E -->|Yes| F[Close & Exit] |
examples/helloWorld/README.md
Outdated
|
|
||
| 1. **Server** listens for WebTransport connections | ||
| 2. **Client** connects and opens streams for each message | ||
| 3. Server responds with "world!" for "hello", otherwise echoes the message |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The README description on line 21 states the server "echoes the message" for non-"hello" messages, but the actual implementation in server/main.go (line 75) sends "I only respond to 'hello' with 'world!'" instead of echoing. The documentation should match the actual behavior.
examples/helloWorld/README.md
Outdated
|
|
||
| ```mermaid | ||
| flowchart TD | ||
| A[Start Server] --> B[Listen on :4433] |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The port number in the flowchart shows ":4433", but the actual server configuration in common/config.go uses port "4430" (line 15). The documentation should reflect the correct port number.
| A[Start Server] --> B[Listen on :4433] | |
| A[Start Server] --> B[Listen on :4430] |
examples/helloWorld/README.md
Outdated
| E --> F[Read Message] | ||
| F --> G{hello?} | ||
| G -->|Yes| H[Send: world!] | ||
| G -->|No| I[Send: echo message] |
Copilot
AI
Dec 30, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flowchart description on line 59 shows "Send: echo message" which does not match the actual server implementation. The server sends "I only respond to 'hello' with 'world!'" for non-"hello" messages, not an echo of the message.
|
@marten-seemann hi I'm sorry if your busy (rightfully so); TLDR in case you didnt see the PR / missed it - do you have any feedback on it? |