diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5006bd6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.24.2-bookworm AS builder + +WORKDIR /app + +COPY . /app + +RUN go mod download + +RUN CGO_ENABLED=0 GOOS=linux go build -o main cmd/main/hello.go + +FROM debian:bookworm-slim + +WORKDIR /app + +COPY --from=builder /app/main . + +CMD ["./main"] diff --git a/cmd/main/hello.go b/cmd/main/hello.go index 90f4aea..7c4e406 100644 --- a/cmd/main/hello.go +++ b/cmd/main/hello.go @@ -308,7 +308,9 @@ func main() { go checkBalanceLoop() go checkTransLoop() - // http.ListenAndServeTLS(config.ListenAddr, "cert.pem", "key.pem", nil) - http.ListenAndServe(cfg.ListenAddr, xfbbroker.CreateApiServer(cfg)) - fmt.Println("Hello, World!") + if cfg.ListenTLS { + http.ListenAndServeTLS(cfg.ListenAddr, cfg.TLSCertFile, cfg.TLSKeyFile, xfbbroker.CreateApiServer(cfg)) + } else { + http.ListenAndServe(cfg.ListenAddr, xfbbroker.CreateApiServer(cfg)) + } } diff --git a/config.go b/config.go index eeb90da..4501d41 100644 --- a/config.go +++ b/config.go @@ -27,6 +27,9 @@ type Config struct { CheckTransInterval int CheckBalanceInterval int ListenAddr string + ListenTLS bool + TLSCertFile string + TLSKeyFile string AuthLocalUrl string AuthCallback string } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..44da885 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + app: + build: + context: . + dockerfile: Dockerfile + volumes: + - ./config.json:/app/config.json:ro + ports: + - "8000:8000"