fireup / example-time-api read public
fireme example: a tiny Go HTTP API with its own Dockerfile
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "encoding/json" |
| 5 | "log" |
| 6 | "net/http" |
| 7 | "os" |
| 8 | "time" |
| 9 | ) |
| 10 | |
| 11 | func main() { |
| 12 | port := os.Getenv("PORT") |
| 13 | if port == "" { |
| 14 | port = "8080" |
| 15 | } |
| 16 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { |
| 17 | w.Header().Set("Content-Type", "application/json") |
| 18 | json.NewEncoder(w).Encode(map[string]string{"utc": time.Now().UTC().Format(time.RFC3339)}) |
| 19 | }) |
| 20 | http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { |
| 21 | w.Write([]byte("ok\n")) |
| 22 | }) |
| 23 | log.Printf("listening on :%s", port) |
| 24 | log.Fatal(http.ListenAndServe(":"+port, nil)) |
| 25 | } |