Skip to content

Instantly share code, notes, and snippets.

@shijuvar
Last active March 5, 2016 09:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save shijuvar/eae8e5baa28ae84674ce to your computer and use it in GitHub Desktop.
Save shijuvar/eae8e5baa28ae84674ce to your computer and use it in GitHub Desktop.
A simple HTTP server in Go
package main
import (
"fmt"
"io"
"log"
"net/http"
)
func helloHandler(res http.ResponseWriter, req *http.Request) {
res.Header().Set(
"Content-Type",
"text/html",
)
io.WriteString(
res,
`<doctype html>
<html>
<head>
<title>Hello Gopher</title>
</head>
<body>
Hello Gopher </br>
It is really awesome that both Docker and Kubernetes are written in Go!
</body>
</html>`,
)
}
func defaultHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Go web app powered by Docker")
}
func main() {
http.HandleFunc("/", defaultHandler)
http.HandleFunc("/hello", helloHandler)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
return
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment