heyogit

fireup / example-time-api read public

fireme example: a tiny Go HTTP API with its own Dockerfile

ACapplb:claude-code-fireupA tiny Go time API with its own Dockerfile8890d3f · 2 months ago
25 lines · 565 B
1package main
2
3import (
4 "encoding/json"
5 "log"
6 "net/http"
7 "os"
8 "time"
9)
10
11func 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}