39 lines
755 B
Go
39 lines
755 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
"github.com/joho/godotenv"
|
|
)
|
|
|
|
func main() {
|
|
// Load environment variables from .env file
|
|
godotenv.Load()
|
|
|
|
// Create new Fiber instance
|
|
app := fiber.New()
|
|
|
|
// Define route handler for "/"
|
|
app.Get("/", func(c *fiber.Ctx) error {
|
|
return c.Status(fiber.StatusOK).JSON(map[string]any{
|
|
"message": fmt.Sprintf("Hello world from Server %s", os.Getenv("SERVER_NAME")),
|
|
"meta": []any{},
|
|
})
|
|
})
|
|
|
|
// Get port from environment variable or default to 3000
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "3000"
|
|
}
|
|
|
|
// Print port
|
|
log.Println("Server now initialized on port", port)
|
|
|
|
// Start server on defined port
|
|
log.Fatal(app.Listen(fmt.Sprintf(":%s", port)))
|
|
}
|