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 { log.Fatal("Error loading .env file") } 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, }) }