Skip to content

Commit

Permalink
Add Makefile for autodeploy and create the base arbo
Browse files Browse the repository at this point in the history
  • Loading branch information
BreizhHardware committed Nov 7, 2024
1 parent fb8f32a commit b7a7a0b
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Variables
BACKEND_DIR=backend
BACKEND_BINARY=backend

# Règles
all: build-backend start-backend

build-backend:
@echo "Building backend..."
cd $(BACKEND_DIR) && go build -o $(BACKEND_BINARY)

start-backend:
@echo "Starting backend..."
cd $(BACKEND_DIR) && ./$(BACKEND_BINARY)

.PHONY: all build-backend start-backend
26 changes: 12 additions & 14 deletions backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,29 @@ type LinkAndDate struct {
}

func getDayAndLink(c *gin.Context) {
//Charge le fichier .env
err := godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file")
}
//Récupération du chemin du fichier contenant les dates et les liens depuis le .env

fileName := os.Getenv("FILE_NAME")
if fileName == "" {
log.Fatalf("FILE_NAME not set in .env")
}

//Récupération de la date du jour
date := time.Now().Format("02-01-2006")

//Lis le fichier de contenant les dates et les liens (date_link.txt par exemple) à son chemin spécifié dans le .env
//Si la date du jour est présente dans le fichier, renvoie le lien associé
//Le fichier doit être sous la forme suivante :
//01-12-2024;https://instagram.com/appen_isen
//Sinon, renvoie un lien par défaut
//Le lien par défault est https://instagram.com/appen_isen
file, err := os.Open(fileName)
if err != nil {
log.Fatalf("Error opening file: %v", err)
}
defer func(file *os.File) {
err := file.Close()
if err != nil {

log.Fatalf("Error closing file: %v", err)
}
}(file)

//Crée une carte pour stocker les dates et les liens
links := make(map[string]string)
scanner := bufio.NewScanner(file)
for scanner.Scan() {
Expand All @@ -61,7 +52,6 @@ func getDayAndLink(c *gin.Context) {
log.Fatalf("Error reading file: %v", err)
}

//Cherche le lien associé à la date du jour
link, exists := links[date]
if !exists {
link = "https://instagram.com/appen_isen"
Expand All @@ -74,11 +64,19 @@ func main() {
gin.SetMode(gin.ReleaseMode)
router := gin.Default()

//Définition de la route /get_day avec la méthode GET et la fonction getDayAndLink qui renvoie le jour sous la forme d'un string (14-12-2024) et un lien sous la forme d'un string (https://www.google.com)
// Serve static files from the frontend directory
router.Static("/static", "./frontend")

// API route
router.GET("/api/get_day", getDayAndLink)

// Serve the index.html file
router.NoRoute(func(c *gin.Context) {
c.File("../frontend/index.html")
})

err := router.Run(":8080")
if err != nil {
return
log.Fatalf("Error starting server: %v", err)
}
}
10 changes: 10 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
coucou
</body>
</html>

0 comments on commit b7a7a0b

Please sign in to comment.