-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
38 lines (32 loc) · 764 Bytes
/
main.go
File metadata and controls
38 lines (32 loc) · 764 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"
"io/ioutil"
"log"
"net/http"
)
// defineFlags contains all the flag definitions, which are called before flag.Parse().
func parseFlags() {
flag.Parse()
}
func main() {
log.Printf("Server started.")
parseFlags()
router := http.NewServeMux()
router.HandleFunc("/koala", HelloKoala)
srv := &http.Server{
Addr: ":8080",
Handler: router,
}
log.Fatal(srv.ListenAndServe())
}
func HelloKoala(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusOK)
VERSION, err := ioutil.ReadFile("VERSION")
if err != nil {
fmt.Fprintln(w, "Error reading VERSION file (<<<SERVICE_NAME>>>): "+err.Error())
return
}
fmt.Fprintln(w, "Hello world! service:<<<SERVICE_NAME>>> version: "+string(VERSION))
}