Created
March 3, 2022 02:33
-
-
Save davidoram/09e444bf957485bb7c2137f36e58f16e to your computer and use it in GitHub Desktop.
Go server with ngrok
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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