init: initial push
This commit is contained in:
38
main.go
Normal file
38
main.go
Normal file
@@ -0,0 +1,38 @@
|
||||
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)))
|
||||
}
|
||||
Reference in New Issue
Block a user