Skip to content

Instantly share code, notes, and snippets.

@davidoram
Created March 3, 2022 02:33
Show Gist options
  • Save davidoram/09e444bf957485bb7c2137f36e58f16e to your computer and use it in GitHub Desktop.
Save davidoram/09e444bf957485bb7c2137f36e58f16e to your computer and use it in GitHub Desktop.
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