summaryrefslogtreecommitdiff
path: root/main.go
blob: ec799df12adfe96b57a16a6c2cba0ce2e98c54d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main

import (
	"flag"
	"io"
	"log"
	"net/http"
)

type handler struct{}

func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/plain")
	io.WriteString(w, "Hello world!")
}

func main() {
	port := flag.String("port", "8080", "Default localhost port")
	flag.Parse()

	mux := http.NewServeMux()

	mux.Handle("/{$}", &handler{})

	srv := http.Server{
		Addr:    ":" + *port,
		Handler: mux,
	}

	log.Printf("Serving on port %s...\n", *port)
	log.Fatal(srv.ListenAndServe())
}