commit 31d1149176398785d87a57bc528890d9cd74ba9a Author: stackops Date: Thu Apr 9 16:53:39 2026 +0300 users-api service diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0a860bc --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.25-alpine AS builder +WORKDIR /src +COPY go.mod ./ +RUN go mod download +COPY . . +RUN go build -o /users-api . + +FROM alpine:3.20 +COPY --from=builder /users-api /usr/local/bin/users-api +EXPOSE 8080 +ENTRYPOINT ["users-api"] diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..bdef392 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module users-api + +go 1.25.6 diff --git a/main.go b/main.go new file mode 100644 index 0000000..75aea4f --- /dev/null +++ b/main.go @@ -0,0 +1,37 @@ +package main + +import ( + "encoding/json" + "log" + "net/http" + "os" +) + +type User struct { + ID int `json:"id"` + Name string `json:"name"` +} + +var users = []User{ + {1, "Alice"}, + {2, "Bob"}, + {3, "Charlie"}, +} + +func main() { + http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(200) + }) + + http.HandleFunc("/users", func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(users) + }) + + port := os.Getenv("PORT") + if port == "" { + port = "8080" + } + log.Printf("users-api listening on :%s", port) + log.Fatal(http.ListenAndServe(":"+port, nil)) +} diff --git a/stackfile.toml b/stackfile.toml new file mode 100644 index 0000000..b0d43fa --- /dev/null +++ b/stackfile.toml @@ -0,0 +1,14 @@ +[app] +name = "users-api" +image = "git.nodeup.ru/stackops/users-api:latest" +replicas = 1 +port = 8080 + +[ingress] +host = "users.app.nodeup.ru" +path = "/" +tls = true + +[health] +liveness = "/healthz" +readiness = "/healthz"