docker added

This commit is contained in:
darius 2024-02-13 18:45:08 +01:00
parent 3dcadccc0c
commit 1555a97843
5 changed files with 50 additions and 0 deletions

19
Dockerfile Normal file
View File

@ -0,0 +1,19 @@
# Use an official Golang runtime as a parent image
FROM golang:latest
# Set the working directory to /app
WORKDIR .
# Copy the current directory contents into the container at /app
COPY . .
# Download and install any required dependencies
RUN go mod download
# Build the Go app
RUN go build -o main .
# Expose port 8080 for incoming traffic
EXPOSE 4002
# Define the command to run the app when the container starts
CMD ["go", "run"]

8
docker-compose.yml Normal file
View File

@ -0,0 +1,8 @@
version: '3.8'
services:
api:
build: .
ports:
- "4002:4002"
restart: unless-stopped

2
go.mod
View File

@ -1 +1,3 @@
module portfolio-backend module portfolio-backend
go 1.22

BIN
main Normal file

Binary file not shown.

21
main.go Normal file
View File

@ -0,0 +1,21 @@
package main
import "net/http"
func main() {
// Create a new request multiplexer
// Take incoming requests and dispatch them to the matching handlers
mux := http.NewServeMux()
// Register the routes and handlers
mux.HandleFunc("GET /", test)
// Run the server
http.ListenAndServe(":4002", mux)
}
func test(w http.ResponseWriter, r *http.Request) {
println("test123")
w.Write([]byte("test"))
}