Skip to content

Instantly share code, notes, and snippets.

@dustinkirkland
Created July 13, 2018 20:42
Show Gist options
  • Save dustinkirkland/c51ad3fc896d12fcfcce7c38d3385419 to your computer and use it in GitHub Desktop.
Save dustinkirkland/c51ad3fc896d12fcfcce7c38d3385419 to your computer and use it in GitHub Desktop.
petname-http.go
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