This page provides information about the sample apps available and how to test them using curl commands and a Go client program for WebSocket connections.
The Files App provides APIs to upload, download, list, and delete files. Below are the curl commands to test these endpoints:
curl --http1.1 -X POST -F "file=@/path/to/your/file.txt" http:///api/v1/files/upload
curl --http1.1 -X GET "http:///api/v1/files/download?filename=file.txt" -o downloaded_file.txt
curl --http1.1 -X GET http:///api/v1/files
curl --http1.1 -X DELETE http:///api/v1/files/file.txt
The Chat App allows users to send and receive messages in real-time. You can start using the Chat App by visiting the following URL:
https:///chat
Once on the page, you can interact with the chat interface to send and receive messages.
To understand the behavior of the Chat App, you can open multiple browser tabs or sessions with the same URL (http:///chat) and observe how messages are synchronized across all sessions in real-time.
The WebSocket App allows clients to establish WebSocket connections and exchange messages. Below is a Go client program to test the WebSocket connection:
package main
import (
"fmt"
"sync"
"github.com/gorilla/websocket"
)
func main() {
// Define the WebSocket URL with the cluster name
socketUrl := fmt.Sprintf("wss://%s/ws", "")
// Use a WaitGroup to wait for all goroutines to finish
var wg sync.WaitGroup
// Number of parallel connections
const numConnections = 100
// Iterate to create multiple connections
for i := 1; i <= numConnections; i++ {
wg.Add(1) // Increment WaitGroup counter
// Launch a goroutine for each connection
go func(connID int) {
defer wg.Done() // Decrement counter when the goroutine completes
// Establish the WebSocket connection
conn, _, err := websocket.DefaultDialer.Dial(socketUrl, nil)
if err != nil {
fmt.Printf("[Connection %d] Failed to establish connection: %s\n", connID, err.Error())
return
}
defer conn.Close()
fmt.Printf("[Connection %d] Connected successfully!\n", connID)
// Send a message to the server
message := fmt.Sprintf("Hello from client %d!!", connID)
err = conn.WriteMessage(websocket.TextMessage, []byte(message))
if err != nil {
fmt.Printf("[Connection %d] Failed to send message: %s\n", connID, err.Error())
return
}
// Read a response message from the server
_, msg, err := conn.ReadMessage()
if err != nil {
fmt.Printf("[Connection %d] Failed to receive message: %s\n", connID, err.Error())
return
}
fmt.Printf("[Connection %d] Message received from server: %s\n", connID, msg)
}(i) // Pass the connection ID to the goroutine
}
// Wait for all goroutines to complete
wg.Wait()
fmt.Println("All connections completed.")
}
Replace the WebSocket URL in the code with the appropriate URL for your environment.