Created
January 20, 2017 00:44
-
-
Save mihneadb/39a6075a63b697c5f5030b6552750446 to your computer and use it in GitHub Desktop.
Hello world server in Go using net/http
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 | |
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