1
0
Fork 0
forked from goffee/cup
cup/controllers/home.go

55 lines
1.3 KiB
Go
Raw Normal View History

2024-09-12 19:15:38 -04:00
// Copyright 2023 Harran Ali <harran.m@gmail.com>. All rights reserved.
// Copyright (c) 2024 Zeni Kim <zenik@smarteching.com>
// Use of this source code is governed by MIT-style
// license that can be found in the LICENSE file.
2024-09-15 15:05:45 -04:00
package controllers
2024-09-12 19:15:38 -04:00
import (
2024-09-28 13:30:49 -04:00
"os"
"strconv"
2024-09-12 19:15:38 -04:00
"git.smarteching.com/goffee/core"
2024-09-28 13:30:49 -04:00
"git.smarteching.com/goffee/core/template/components"
2024-09-12 19:15:38 -04:00
)
// Show home page
func WelcomeHome(c *core.Context) *core.Response {
2024-09-28 13:30:49 -04:00
// check if template engine is enable
TemplateEnableStr := os.Getenv("TEMPLATE_ENABLE")
if TemplateEnableStr == "" {
TemplateEnableStr = "false"
}
TemplateEnable, _ := strconv.ParseBool(TemplateEnableStr)
if TemplateEnable {
2024-10-07 19:12:28 -04:00
// first, include all compoments
2024-09-28 13:30:49 -04:00
type templateData struct {
2024-10-07 19:12:28 -04:00
PageCard components.PageCard
2024-09-28 13:30:49 -04:00
}
2024-10-07 19:12:28 -04:00
// now fill data of the components
2024-09-28 13:30:49 -04:00
tmplData := templateData{
2024-10-07 19:12:28 -04:00
PageCard: components.PageCard{
CardTitle: "Golang Framework",
CardBody: "Welcome to Goffee",
2024-09-28 13:30:49 -04:00
},
}
2024-10-07 19:12:28 -04:00
return c.Response.Template("welcome.html", tmplData)
2024-09-28 13:30:49 -04:00
} else {
message := "{\"message\": \"Welcome to Goffee\"}"
return c.Response.Json(message)
}
2024-09-12 19:15:38 -04:00
}
// Show dashboard
func WelcomeToDashboard(c *core.Context) *core.Response {
message := "{\"message\": \"Welcome to Dashboard\"}"
return c.Response.Json(message)
}