Go server with ngrok
This file contains 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