Open platform to collect and prioritize feedback
better org
goenningdabb98acdcff
diff --git a/handler/index.go b/handler/index.gonew file mode 100644index 000000000..b9568fb5e--- /dev/null+++ b/handler/index.go@@ -0,0 +1,25 @@+package handler++import (+ "net/http"++ "github.com/WeCanHearYou/wchy/context"+ "github.com/gin-gonic/gin"+)++type indexHandlder struct {+ ctx *context.WchyContext+}++// Index handles initial page+func Index(ctx *context.WchyContext) gin.HandlerFunc {+ return indexHandlder{ctx: ctx}.get()+}++func (h indexHandlder) get() gin.HandlerFunc {+ return func(c *gin.Context) {+ c.HTML(http.StatusOK, "index.html", gin.H{+ "Title": c.MustGet("Tenant"),+ })+ }+}diff --git a/handler/status.go b/handler/status.goindex 74115e255..d927cbdb1 100644--- a/handler/status.go+++ b/handler/status.go@@ -1,6 +1,7 @@package handlerimport (+ "net/http""runtime""time"@@ -19,7 +20,7 @@ func Status(ctx *context.WchyContext) gin.HandlerFunc {func (h statusHandler) get() gin.HandlerFunc {return func(c *gin.Context) {- c.JSON(200, gin.H{+ c.JSON(http.StatusOK, gin.H{"build": h.ctx.Settings.BuildTime,"healthy": gin.H{"database": h.ctx.Health.IsDatabaseOnline(),diff --git a/handler/tenant.go b/handler/tenant.goindex bc541a539..9d346302a 100644--- a/handler/tenant.go+++ b/handler/tenant.go@@ -1,6 +1,8 @@package handlerimport (+ "net/http"+"github.com/WeCanHearYou/wchy/context""github.com/WeCanHearYou/wchy/service""github.com/gin-gonic/gin"@@ -19,9 +21,9 @@ func (h tenantHandlers) byDomain() gin.HandlerFunc {return func(c *gin.Context) {tenant, err := h.ctx.Tenant.GetByDomain(c.Param("domain"))if err == service.ErrNotFound {- c.Status(404)+ c.Status(http.StatusNotFound)} else {- c.JSON(200, tenant)+ c.JSON(http.StatusOK, tenant)}}}diff --git a/router/router.go b/router/router.goindex 77c5e88a3..ecbe80a24 100644--- a/router/router.go+++ b/router/router.go@@ -1,7 +1,6 @@package routerimport (- "net/http""os""path/filepath"@@ -31,11 +30,7 @@ func GetMainEngine(ctx *context.WchyContext) *gin.Engine {router.LoadHTMLGlob("views/*")}- router.GET("/", func(c *gin.Context) {- c.HTML(http.StatusOK, "index.tmpl", gin.H{- "title": c.MustGet("Tenant"),- })- })+ router.GET("/", handler.Index(ctx))api := router.Group("/api"){diff --git a/service/tenant.go b/service/tenant.goindex eee327f6c..fdcb8fbf9 100644--- a/service/tenant.go+++ b/service/tenant.go@@ -24,7 +24,7 @@ func (svc PostgresTenantService) GetByDomain(domain string) (*model.Tenant, errorow := svc.DB.QueryRow("SELECT id, name, subdomain FROM tenants WHERE subdomain = $1", extractSubdomain(domain))err := row.Scan(&tenant.ID, &tenant.Name, &tenant.Domain)- if err == sql.ErrNoRows {+ if err != nil {return nil, ErrNotFound}diff --git a/views/index.html b/views/index.htmlnew file mode 100644index 000000000..472706e93--- /dev/null+++ b/views/index.html@@ -0,0 +1,5 @@+<html>+ <h1>+ Hello World: {{ .Title }}+ </h1>+</html>\ No newline at end of filediff --git a/views/index.tmpl b/views/index.tmpldeleted file mode 100644index 62b3f4ef2..000000000--- a/views/index.tmpl+++ /dev/null@@ -1,5 +0,0 @@-<html>- <h1>- Hello World: {{ .title }}- </h1>-</html>\ No newline at end of file