Initial commit
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
FROM golang:1.23-alpine AS build
|
||||
WORKDIR /src
|
||||
COPY go.mod go.sum* ./
|
||||
RUN go mod download
|
||||
COPY . .
|
||||
ARG SERVICE=api
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w" -o /out/service ./cmd/${SERVICE}
|
||||
|
||||
FROM gcr.io/distroless/static-debian12:nonroot
|
||||
COPY --from=build /out/service /service
|
||||
USER nonroot:nonroot
|
||||
ENTRYPOINT ["/service"]
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
.PHONY: test fmt vet
|
||||
test:
|
||||
go test ./...
|
||||
fmt:
|
||||
gofmt -w ./cmd
|
||||
vet:
|
||||
go vet ./...
|
||||
@@ -0,0 +1 @@
|
||||
Run `go mod tidy`, then `go test ./...`. Services are deliberately incomplete placeholders.
|
||||
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
_ = json.NewEncoder(w).Encode(map[string]string{"status": "ok", "service": "api"})
|
||||
})
|
||||
// Placeholder only: registration/authentication is not implemented.
|
||||
mux.HandleFunc("POST /api/v1/auth/register", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "registration not implemented", http.StatusNotImplemented)
|
||||
})
|
||||
addr := os.Getenv("API_ADDR")
|
||||
if addr == "" {
|
||||
addr = ":8080"
|
||||
}
|
||||
srv := &http.Server{Addr: addr, Handler: mux, ReadHeaderTimeout: 5 * time.Second}
|
||||
log.Printf("API listening on %s", addr)
|
||||
log.Fatal(srv.ListenAndServe())
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHealthEndpoint(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/healthz", nil)
|
||||
rec := httptest.NewRecorder()
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(200) })
|
||||
mux.ServeHTTP(rec, req)
|
||||
if rec.Code != 200 {
|
||||
t.Fatalf("want 200, got %d", rec.Code)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte("ok\n"))
|
||||
})
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "key directory not implemented", http.StatusNotImplemented)
|
||||
})
|
||||
srv := &http.Server{Addr: ":8082", Handler: mux, ReadHeaderTimeout: 5 * time.Second}
|
||||
log.Printf("keyserver listening on %s", srv.Addr)
|
||||
log.Fatal(srv.ListenAndServe())
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte("ok\n"))
|
||||
})
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "push dispatcher not implemented", http.StatusNotImplemented)
|
||||
})
|
||||
srv := &http.Server{Addr: ":8083", Handler: mux, ReadHeaderTimeout: 5 * time.Second}
|
||||
log.Printf("push service listening on %s", srv.Addr)
|
||||
log.Fatal(srv.ListenAndServe())
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("GET /healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write([]byte("ok\n"))
|
||||
})
|
||||
mux.HandleFunc("GET /ws/v1/signaling", func(w http.ResponseWriter, r *http.Request) {
|
||||
// Deliberately disabled until authentication, authorization, message limits,
|
||||
// replay protection and routing are implemented.
|
||||
http.Error(w, "signaling is not enabled in scaffold", http.StatusNotImplemented)
|
||||
})
|
||||
addr := os.Getenv("SIGNALING_ADDR")
|
||||
if addr == "" {
|
||||
addr = ":8081"
|
||||
}
|
||||
srv := &http.Server{Addr: addr, Handler: mux, ReadHeaderTimeout: 5 * time.Second}
|
||||
log.Printf("signaling service listening on %s", addr)
|
||||
log.Fatal(srv.ListenAndServe())
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
module github.com/ee2e-phone-calls/backend
|
||||
|
||||
go 1.23
|
||||
Reference in New Issue
Block a user