2023-09-29 22:22:23 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/joho/godotenv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
err := godotenv.Load()
|
|
|
|
if err != nil {
|
2023-09-29 23:25:00 +02:00
|
|
|
log.Println("Error loading .env file -- ignore if production")
|
2023-09-29 22:22:23 +02:00
|
|
|
}
|
|
|
|
r := gin.Default()
|
|
|
|
r.GET("/", getLauncherJson)
|
|
|
|
r.Run(fmt.Sprintf("0.0.0.0:%s", os.Getenv("PORT_LISTENING")))
|
|
|
|
}
|
|
|
|
|
|
|
|
func getLauncherJson(c *gin.Context) {
|
|
|
|
res, err := http.Get(os.Getenv("JSON_LOCATION"))
|
|
|
|
if err != nil {
|
|
|
|
respondErrorToClient(c, "Error getting the json file")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if res.StatusCode != http.StatusOK {
|
|
|
|
respondErrorToClient(c, "Error getting the json file")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
body, err := io.ReadAll(res.Body)
|
|
|
|
if err != nil {
|
|
|
|
respondErrorToClient(c, "Error getting the json file")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
c.Data(http.StatusOK, "application/json", body)
|
|
|
|
}
|
|
|
|
|
|
|
|
func respondErrorToClient(c *gin.Context, msg string) {
|
|
|
|
log.Println(msg)
|
|
|
|
c.JSON(http.StatusInternalServerError, gin.H{
|
|
|
|
"error": msg,
|
|
|
|
})
|
|
|
|
}
|