Skip to content

Commit 3c658f3

Browse files
feat: added api address
1 parent b2685e6 commit 3c658f3

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

Dockerfile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11

22
# The build stage
3-
FROM golang:1.24 as builder
3+
FROM golang:1.24 AS builder
44
WORKDIR /app
5+
6+
# Install CA certificates
7+
RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*
8+
59
COPY . .
6-
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o api cmd/api/*.go
10+
RUN CGO_ENABLED=0 GOOS=linux go build -o api ./cmd/api
711

812
# The run stage
913
FROM scratch
1014
WORKDIR /app
15+
1116
# Copy CA certificates
1217
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
1318
COPY --from=builder /app/api .
19+
1420
EXPOSE 8080
1521
CMD ["./api"]

cmd/api/api.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ func (app *application) run(mux http.Handler) error {
204204
}
205205

206206
// Implementing graceful shutdown
207-
shutdown := make(chan error)
207+
shutdown := make(chan error, 1)
208208

209209
go func() {
210210
quit := make(chan os.Signal, 1)
@@ -217,7 +217,11 @@ func (app *application) run(mux http.Handler) error {
217217

218218
app.logger.Infow("signal caught", "signal", s.String())
219219

220-
shutdown <- srv.Shutdown(ctx)
220+
if err := srv.Shutdown(ctx); err != nil {
221+
shutdown <- err
222+
} else {
223+
close(shutdown) // Close channel when done
224+
}
221225
}()
222226

223227
app.logger.Infow("server has started", "addr", app.config.addr, "env", app.config.env)
@@ -227,8 +231,9 @@ func (app *application) run(mux http.Handler) error {
227231
return err
228232
}
229233

230-
err = <-shutdown
231-
if err != nil {
234+
err = srv.ListenAndServe()
235+
if err != nil && !errors.Is(err, http.ErrServerClosed) {
236+
app.logger.Errorw("server error", "error", err)
232237
return err
233238
}
234239

cmd/api/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func NewLogger() (*zap.SugaredLogger, error) {
7777
return logger.Sugar(), nil
7878
}
7979

80-
var version = "1.1.0"
80+
var version = "1.2.0"
8181

8282
// @title Khel API
8383
// @description API for Khel, a complete sport application.

0 commit comments

Comments
 (0)