mySitio / cmd / web / handlers.go
handlers.go
Raw
package main

import "github.com/gofiber/fiber/v2"

func home(c *fiber.Ctx) error {
	Data.Title = "Welcome to My site!"
	sliceOfHeaders := []string{"abt", "proj", "skillz", "articles", "pets", "contact"} //pass in headers sections to populate

	headerSlice, err := openStoreJson("/index/index_headers.json", &sliceOfHeaders)
	if err != nil {
		return err
	}

	//assign headers in the exact order they were given
	Data.Abt = &headerSlice[0]
	Data.Projects_Header = &headerSlice[1]
	Data.Skillz_Header = &headerSlice[2]
	Data.Articles_Header = &headerSlice[3]
	Data.Pets_Header = &headerSlice[4]
	Data.Contact_Header = &headerSlice[5]

	err = c.Render("pages/index", fiber.Map{
		"Data": &Data,
	})
	return err
}

func projects(c *fiber.Ctx) error {
	Data.Title = "My projects!"

	err := c.Render("pages/projects", fiber.Map{
		"Data": &Data,
	})
	return err
}