Template Project
This project demonstrates how to set up a Go application with template rendering, Tailwind CSS, and Parcel for asset bundling.
Prerequisites
Ensure you have the following installed:
- Golang
- Node.js
- npm
Setup
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git
cd recipes/template -
Install dependencies:
npm install
Usage
Building Assets
-
Build the assets:
npm run build
-
Watch assets for changes:
npm run dev
Running the Application
- Start the Fiber application:
go run main.go
Example
Here is an example of how to set up a basic route with template rendering in Go:
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/template/html/v2"
)
func main() {
// Initialize the template engine
engine := html.New("./views", ".html")
// Create a new Fiber instance with the template engine
app := fiber.New(fiber.Config{
Views: engine,
})
// Define a route
app.Get("/", func(c *fiber.Ctx) error {
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
})
})
// Start the server
app.Listen(":3000")
}