mirror of
https://github.com/appen-isen/projet-cal.git
synced 2026-01-18 16:47:38 +01:00
Add Makefile for autodeploy and create the base arbo
This commit is contained in:
16
Makefile
Normal file
16
Makefile
Normal file
@@ -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
|
||||
@@ -16,26 +16,18 @@ 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)
|
||||
@@ -43,11 +35,10 @@ func getDayAndLink(c *gin.Context) {
|
||||
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() {
|
||||
@@ -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"
|
||||
@@ -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
frontend/index.html
Normal file
10
frontend/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
coucou
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user