diff --git a/cmd/web/app-links.go b/cmd/web/app-links.go new file mode 100644 index 0000000..d1e8b3c --- /dev/null +++ b/cmd/web/app-links.go @@ -0,0 +1,124 @@ +package main + +type AppLink struct { + Title string + Url string + Image string + Description string +} + +func getAppLinks(tier, baseUri string) []AppLink { + if tier == "enterprise" { + return getEnterpriseLinks(baseUri) + } else if tier == "creator" { + return getCreatorLinks(baseUri) + } else if tier == "teams" { + return getTeamsLinks(baseUri) + } + + return getStarterLinks(baseUri) +} + +func getStarterLinks(baseUri string) []AppLink { + return []AppLink { + { + Title: "User Management", + Description: "Create users and manage their access", + Image: "/img/panel.jpg", + Url: "https://panel." + baseUri, + }, + { + Title: "Nextcloud", + Description: "Email, Files, Documents", + Image: "/img/nextcloud.jpg", + Url: "https://nextcloud." + baseUri, + }, + { + Title: "Vaultwarden", + Description: "Password Management", + Image: "/img/vaultwarden.jpg", + Url: "https://vaultwarden." + baseUri, + }, + } +} + +func getCreatorLinks(baseUri string) []AppLink { + creatorLinks := []AppLink { + { + Title: "Element and Matrix", + Description: "Team Chat", + Image: "/img/element.jpg", + Url: "https://element." + baseUri, + }, + { + Title: "Wordpress", + Description: "Your website", + Image: "/img/wordpress.jpg", + Url: "https://" + baseUri, + }, + } + + return append(creatorLinks, getStarterLinks(baseUri)...) +} + +func getTeamsLinks(baseUri string) []AppLink { + teamsLinks := []AppLink { + { + Title: "Espo CRM", + Description: "Customer relationship manager", + Image: "/img/espo.jpg", + Url: "https://espocrm." + baseUri, + }, + { + Title: "FreeScout", + Description: "Customer Help Desk", + Image: "/img/freescout.jpg", + Url: "https://freescout." + baseUri, + }, + } + + return append(teamsLinks, getCreatorLinks(baseUri)...) +} + +func getEnterpriseLinks(baseUri string) []AppLink { + enterpriseLinks := []AppLink{ + { + Title: "Jitsi", + Description: "Video Chat", + Image: "/img/jitsi.jpg", + Url: "https://jitsi." + baseUri, + }, + { + Title: "Listmonk", + Description: "Email Marketing", + Image: "/img/listmonk.jpg", + Url: "https://listmonk." + baseUri, + }, + { + Title: "Baserow", + Description: "Visual Databases", + Image: "/img/baserow.jpg", + Url: "https://baserow." + baseUri, + }, + { + Title: "Bookstack", + Description: "Wiki Knowledgebase", + Image: "/img/bookstack.jpg", + Url: "https://bookstack." + baseUri, + }, + { + Title: "Gitea", + Description: "GIT Source Control", + Image: "/img/gitea.jpg", + Url: "https://gitea." + baseUri, + }, + { + Title: "Castopod", + Description: "Podcast Distribution", + Image: "/img/castopod.jpg", + Url: "https://castopod." + baseUri, + }, + } + + return append(enterpriseLinks, getTeamsLinks(baseUri)...) +} \ No newline at end of file diff --git a/cmd/web/handlers.go b/cmd/web/handlers.go index 507b907..7056a72 100644 --- a/cmd/web/handlers.go +++ b/cmd/web/handlers.go @@ -1,7 +1,25 @@ package main -import "net/http" +import ( + "net/http" + "strings" +) func (app *application) home(writer http.ResponseWriter, request *http.Request) { - app.render(writer, request, http.StatusOK, "home.tmpl.html", templateData{}) + domain := request.Host + domainPieces := strings.Split(domain, ".") + var baseURI string + if len(domainPieces) > 1 { + baseURI = domainPieces[len(domainPieces) - 2] + domainPieces[len(domainPieces) - 1] + } else { + baseURI = domain + } + + data := templateData{ + AppLinks: getAppLinks(app.tier, baseURI), + Tier: app.tier, + BaseUri: baseURI, + } + + app.render(writer, request, http.StatusOK, "home.tmpl.html", data) } \ No newline at end of file diff --git a/cmd/web/main.go b/cmd/web/main.go index eea8c94..0956d40 100644 --- a/cmd/web/main.go +++ b/cmd/web/main.go @@ -11,11 +11,14 @@ import ( type application struct { logger *slog.Logger templateCache map[string]*template.Template + tier string } func main() { //Get env variables addr := flag.String("addr", ":4000", "HTTP network address") + tier := flag.String("tier", "starter", "tier the core is on") + flag.Parse() //Set up logger logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{ AddSource: true, @@ -30,6 +33,7 @@ func main() { app := application { logger: logger, templateCache: templateCache, + tier: *tier, } err = http.ListenAndServe(*addr, app.routes()) diff --git a/cmd/web/templates.go b/cmd/web/templates.go index 0a43678..d86821d 100644 --- a/cmd/web/templates.go +++ b/cmd/web/templates.go @@ -7,6 +7,8 @@ import ( type templateData struct { BaseUri string + AppLinks []AppLink + Tier string } func newTemplateCache() (map[string]*template.Template, error) { diff --git a/ui/html/pages/home.tmpl.html b/ui/html/pages/home.tmpl.html index fd6a007..a0138ce 100644 --- a/ui/html/pages/home.tmpl.html +++ b/ui/html/pages/home.tmpl.html @@ -1,5 +1,19 @@ {{define "title"}}Home{{end}} {{define "main"}} - yo + + Apps for {{.BaseUri}} on the {{.Tier}} tier. + + + {{range .AppLinks}} + + + {{.Title}} + {{.Description}} + + + + {{end}} + + {{end}} \ No newline at end of file diff --git a/ui/html/partials/nav.tmpl.html b/ui/html/partials/nav.tmpl.html index c3fffde..d34878d 100644 --- a/ui/html/partials/nav.tmpl.html +++ b/ui/html/partials/nav.tmpl.html @@ -1,5 +1,7 @@ {{define "nav"}} - - Home + + Home + Login + VPN {{end}} \ No newline at end of file
{{.Description}}