heyogit

fireup / example-time-api read public

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

A tiny Go time API with its own Dockerfile

Browse files
ACapplb:claude-code-fireupcommitted 2 months ago · Oct 19, 2026· committed by heyo remotecommit 8890d3fc70b53dca03fe6c486ab1c2f5de6bbedd

Showing 4 changed files with 53 additions and 0 deletions.

addedDockerfile+11−0View file
@@ -0,0 +1,11 @@
+FROM golang:1.23 AS build
+WORKDIR /src
+COPY go.mod ./
+COPY *.go ./
+RUN CGO_ENABLED=0 go build -o /out/time-api .
+
+FROM gcr.io/distroless/static-debian12
+COPY --from=build /out/time-api /time-api
+ENV PORT=8080
+EXPOSE 8080
+ENTRYPOINT ["/time-api"]
addedREADME.md+14−0View file
@@ -0,0 +1,14 @@
+# time-api
+
+A tiny HTTP API that returns the current UTC time.
+
+- `GET /` returns `{"utc": "2026-10-19T21:00:00Z"}`
+- `GET /healthz` returns `ok`
+
+It listens on `$PORT` (default 8080).
+
+```sh
+go run .
+# or
+docker build -t time-api . && docker run -p 8080:8080 time-api
+```
addedgo.mod+3−0View file
@@ -0,0 +1,3 @@
+module example.com/time-api
+
+go 1.23
addedmain.go+25−0View file
@@ -0,0 +1,25 @@
+package main
+
+import (
+ "encoding/json"
+ "log"
+ "net/http"
+ "os"
+ "time"
+)
+
+func main() {
+ port := os.Getenv("PORT")
+ if port == "" {
+ port = "8080"
+ }
+ http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ json.NewEncoder(w).Encode(map[string]string{"utc": time.Now().UTC().Format(time.RFC3339)})
+ })
+ http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
+ w.Write([]byte("ok\n"))
+ })
+ log.Printf("listening on :%s", port)
+ log.Fatal(http.ListenAndServe(":"+port, nil))
+}