-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (32 loc) · 747 Bytes
/
main.go
File metadata and controls
38 lines (32 loc) · 747 Bytes
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
33
34
35
36
37
38
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
)
var pathFlag = flag.String("path", "", "specify the URL root")
func main() {
flag.Parse()
if *pathFlag == "" {
log.Fatal("Missing path")
}
path := *pathFlag
http.HandleFunc(fmt.Sprintf("/%s", path), func(rw http.ResponseWriter, r *http.Request) {
host, err := os.Hostname()
if err != nil {
http.Error(rw, err.Error(), http.StatusInternalServerError)
}
fmt.Fprintln(rw, host)
fmt.Fprintln(rw, r.URL.String())
})
http.HandleFunc(fmt.Sprintf("/%s/health", path), func(rw http.ResponseWriter, r *http.Request) {
fmt.Fprint(rw, "OK")
})
log.Print("Server starting at :8080")
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal(err)
}
}