Created
July 13, 2018 20:42
-
-
Save dustinkirkland/c51ad3fc896d12fcfcce7c38d3385419 to your computer and use it in GitHub Desktop.
petname-http.go
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 | |
import ( | |
"flag" | |
"fmt" | |
"log" | |
"net/http" | |
"github.com/dustinkirkland/golang-petname" | |
) | |
var ( | |
words = flag.Int("words", 2, "The number of words in the pet name") | |
separator = flag.String("separator", "-", "The separator between words in the pet name") | |
) | |
func handler(w http.ResponseWriter, r *http.Request) { | |
fmt.Fprintf(w, "%s", petname.Generate(*words, *separator)) | |
} | |
func main() { | |
http.HandleFunc("/", handler) | |
log.Fatal(http.ListenAndServe(":9876", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment