Skip to content

Instantly share code, notes, and snippets.

@davidoram
Created Mar 3, 2022
Embed
What would you like to do?
Go server with ngrok
package main
//
// Run the server
// go run server.go
//
// Expose via ngrok
// ngrok http 8080
//
//
import (
"fmt"
"math/rand"
"net/http"
"time"
)
func main() {
http.HandleFunc("/", HelloServer)
http.ListenAndServe(":8080", nil)
}
func shuffle(src []string) []string {
final := make([]string, len(src))
rand.Seed(time.Now().UTC().UnixNano())
perm := rand.Perm(len(src))
for i, v := range perm {
final[v] = src[i]
}
return final
}
func HelloServer(w http.ResponseWriter, r *http.Request) {
peeps := []string{"Dave", "Andy", "Matt", "Manoj", "Ildo", "Shiny", "Kev", "Nick"}
fmt.Fprintf(w, "%v", shuffle(peeps))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment