added example code to start from

This commit is contained in:
Frank Wünsche
2024-11-11 13:03:54 +01:00
parent e7becca311
commit 8776b79dbf
+25
View File
@@ -0,0 +1,25 @@
package main
import (
"fmt"
"math/rand"
"net/http"
"strconv"
"time"
)
func handler(w http.ResponseWriter, r *http.Request) {
rand.Seed(time.Now().UnixNano())
// Get the 'min' and 'max' query parameters from the URL
minParam := r.URL.Query().Get("min")
maxParam := r.URL.Query().Get("max")
// Convert the parameters to integers
min, _ := strconv.Atoi(minParam)
max, _ := strconv.Atoi(maxParam)
// Generate a random number within the specified range
randomNumber := rand.Intn(max-min+1) + min
fmt.Fprintf(w, "Random Number: %d", randomNumber)
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}