Skip to content

Instantly share code, notes, and snippets.

@mihneadb
Created January 20, 2017 00:44
Show Gist options
  • Save mihneadb/39a6075a63b697c5f5030b6552750446 to your computer and use it in GitHub Desktop.
Save mihneadb/39a6075a63b697c5f5030b6552750446 to your computer and use it in GitHub Desktop.
Hello world server in Go using net/http
package main
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
var name string
found := r.URL.Query().Get("name")
if found != "" {
name = found
} else {
name = "world"
}
fmt.Fprintf(w, "Hello, %s!", name)
}
func main() {
fmt.Print("Go to http://localhost:3000/?name=Neo\n")
http.HandleFunc("/", handler)
http.ListenAndServe(":3000", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment