Open platform to collect and prioritize feedback
plural to singular
goenning45d183896bc7
diff --git a/context/wchy.go b/context/wchy.goindex e2dd626bf..b50e84e3f 100644--- a/context/wchy.go+++ b/context/wchy.go@@ -1,6 +1,6 @@package context-import "github.com/WeCanHearYou/wchy/services"+import "github.com/WeCanHearYou/wchy/service"// WchySettings is an application-wide settingstype WchySettings struct {@@ -9,7 +9,7 @@ type WchySettings struct {// WchyContext is an application-wide contexttype WchyContext struct {- Health services.HealthCheckService- Tenant services.TenantService+ Health service.HealthCheckService+ Tenant service.TenantServiceSettings WchySettings}diff --git a/handlers/handlers_helper_test.go b/handler/handler_helper_test.gosimilarity index 97%rename from handlers/handlers_helper_test.gorename to handler/handler_helper_test.goindex 0c2a29e88..c0a6a5970 100644--- a/handlers/handlers_helper_test.go+++ b/handler/handler_helper_test.go@@ -1,4 +1,4 @@-package handlers_test+package handler_testimport ("encoding/json"diff --git a/handlers/status.go b/handler/status.gosimilarity index 97%rename from handlers/status.gorename to handler/status.goindex 7d0af1101..74115e255 100644--- a/handlers/status.go+++ b/handler/status.go@@ -1,4 +1,4 @@-package handlers+package handlerimport ("runtime"diff --git a/handlers/status_test.go b/handler/status_test.gosimilarity index 86%rename from handlers/status_test.gorename to handler/status_test.goindex f03b60bd7..29c50e18f 100644--- a/handlers/status_test.go+++ b/handler/status_test.go@@ -1,10 +1,10 @@-package handlers_test+package handler_testimport ("testing""github.com/WeCanHearYou/wchy/context"- "github.com/WeCanHearYou/wchy/handlers"+ "github.com/WeCanHearYou/wchy/handler". "github.com/onsi/gomega")@@ -26,7 +26,7 @@ func TestStatusHandler(t *testing.T) {}server := NewTestServer()- server.register(handlers.Status(ctx))+ server.register(handler.Status(ctx))status, query := server.request()Expect(query.String("build")).To(Equal("today"))diff --git a/handlers/tenant.go b/handler/tenant.gosimilarity index 84%rename from handlers/tenant.gorename to handler/tenant.goindex e49544a53..bc541a539 100644--- a/handlers/tenant.go+++ b/handler/tenant.go@@ -1,8 +1,8 @@-package handlers+package handlerimport ("github.com/WeCanHearYou/wchy/context"- "github.com/WeCanHearYou/wchy/services"+ "github.com/WeCanHearYou/wchy/service""github.com/gin-gonic/gin")@@ -18,7 +18,7 @@ func TenantByDomain(ctx *context.WchyContext) gin.HandlerFunc {func (h tenantHandlers) byDomain() gin.HandlerFunc {return func(c *gin.Context) {tenant, err := h.ctx.Tenant.GetByDomain(c.Param("domain"))- if err == services.ErrNotFound {+ if err == service.ErrNotFound {c.Status(404)} else {c.JSON(200, tenant)diff --git a/handlers/tenant_test.go b/handler/tenant_test.gosimilarity index 63%rename from handlers/tenant_test.gorename to handler/tenant_test.goindex 318c2770e..b27d36106 100644--- a/handlers/tenant_test.go+++ b/handler/tenant_test.go@@ -1,32 +1,32 @@-package handlers_test+package handler_testimport ("testing""github.com/WeCanHearYou/wchy/context"- "github.com/WeCanHearYou/wchy/handlers"- "github.com/WeCanHearYou/wchy/models"- "github.com/WeCanHearYou/wchy/services"+ "github.com/WeCanHearYou/wchy/handler"+ "github.com/WeCanHearYou/wchy/model"+ "github.com/WeCanHearYou/wchy/service". "github.com/onsi/gomega")type inMemoryTenantService struct {- tenants []*models.Tenant+ tenants []*model.Tenant}-func (svc inMemoryTenantService) GetByDomain(domain string) (*models.Tenant, error) {+func (svc inMemoryTenantService) GetByDomain(domain string) (*model.Tenant, error) {for _, tenant := range svc.tenants {if tenant.Domain == domain {return tenant, nil}}- return nil, services.ErrNotFound+ return nil, service.ErrNotFound}var ctx *context.WchyContext = &context.WchyContext{- Tenant: &inMemoryTenantService{tenants: []*models.Tenant{- &models.Tenant{ID: 1, Name: "Orange Inc.", Domain: "orange"},- &models.Tenant{ID: 2, Name: "The Triathlon Shop", Domain: "trishop"},+ Tenant: &inMemoryTenantService{tenants: []*model.Tenant{+ &model.Tenant{ID: 1, Name: "Orange Inc.", Domain: "orange"},+ &model.Tenant{ID: 2, Name: "The Triathlon Shop", Domain: "trishop"},}},}@@ -35,7 +35,7 @@ func TestTenantHandler_404(t *testing.T) {server := NewTestServer()server.param("domain", "unknown")- server.register(handlers.TenantByDomain(ctx))+ server.register(handler.TenantByDomain(ctx))status, _ := server.request()Expect(status).To(Equal(404))@@ -46,7 +46,7 @@ func TestTenantHandler_200(t *testing.T) {server := NewTestServer()server.param("domain", "trishop")- server.register(handlers.TenantByDomain(ctx))+ server.register(handler.TenantByDomain(ctx))status, query := server.request()Expect(query.Int("id")).To(Equal(2))diff --git a/main.go b/main.goindex fc0069350..1a13fe5aa 100644--- a/main.go+++ b/main.go@@ -9,7 +9,7 @@ import ("github.com/WeCanHearYou/wchy/context""github.com/WeCanHearYou/wchy/env""github.com/WeCanHearYou/wchy/router"- "github.com/WeCanHearYou/wchy/services"+ "github.com/WeCanHearYou/wchy/service"logging "github.com/op/go-logging")@@ -25,8 +25,8 @@ func init() {db, _ = sql.Open("postgres", os.Getenv("DATABASE_URL"))ctx = &context.WchyContext{- Health: &services.PostgresHealthCheckService{DB: db},- Tenant: &services.PostgresTenantService{DB: db},+ Health: &service.PostgresHealthCheckService{DB: db},+ Tenant: &service.PostgresTenantService{DB: db},Settings: context.WchySettings{BuildTime: buildtime,},diff --git a/models/tenant.go b/model/tenant.gosimilarity index 90%rename from models/tenant.gorename to model/tenant.goindex 12b062250..43f83e40d 100644--- a/models/tenant.go+++ b/model/tenant.go@@ -1,4 +1,4 @@-package models+package model//Tenant represents a tenanttype Tenant struct {diff --git a/router/router.go b/router/router.goindex 64ac2e367..06a1e8509 100644--- a/router/router.go+++ b/router/router.go@@ -7,7 +7,7 @@ import ("strings""github.com/WeCanHearYou/wchy/context"- "github.com/WeCanHearYou/wchy/handlers"+ "github.com/WeCanHearYou/wchy/handler""github.com/WeCanHearYou/wchy/env""github.com/gin-gonic/gin"@@ -64,8 +64,8 @@ func GetMainEngine(ctx *context.WchyContext) *gin.Engine {api := router.Group("/api"){- api.GET("/status", handlers.Status(ctx))- api.GET("/tenants/:domain", handlers.TenantByDomain(ctx))+ api.GET("/status", handler.Status(ctx))+ api.GET("/tenants/:domain", handler.TenantByDomain(ctx))}return router}diff --git a/services/errors.go b/service/errors.gosimilarity index 87%rename from services/errors.gorename to service/errors.goindex 1b0acfc8c..0429629df 100644--- a/services/errors.go+++ b/service/errors.go@@ -1,4 +1,4 @@-package services+package serviceimport ("errors"diff --git a/services/health.go b/service/health.gosimilarity index 96%rename from services/health.gorename to service/health.goindex 9335db64b..01db9666e 100644--- a/services/health.go+++ b/service/health.go@@ -1,4 +1,4 @@-package services+package serviceimport "database/sql"diff --git a/services/health_test.go b/service/health_test.gosimilarity index 81%rename from services/health_test.gorename to service/health_test.goindex 059ee2299..e6d746763 100644--- a/services/health_test.go+++ b/service/health_test.go@@ -1,12 +1,12 @@-package services_test+package service_testimport ("fmt""testing"- "github.com/WeCanHearYou/wchy/services"sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"+ "github.com/WeCanHearYou/wchy/service". "github.com/onsi/gomega")@@ -17,7 +17,7 @@ func TestHealthCheckService_IsDatabaseOnline_Error(t *testing.T) {defer db.Close()mock.ExpectQuery("SELECT now()").WillReturnError(fmt.Errorf("some error"))- svc := &services.PostgresHealthCheckService{DB: db}+ svc := &service.PostgresHealthCheckService{DB: db}Expect(svc.IsDatabaseOnline()).To(BeFalse())@@ -31,7 +31,7 @@ func TestHealthCheckService_IsDatabaseOnline_Success(t *testing.T) {defer db.Close()mock.ExpectQuery("SELECT now()").WillReturnRows(sqlmock.NewRows([]string{}))- svc := &services.PostgresHealthCheckService{DB: db}+ svc := &service.PostgresHealthCheckService{DB: db}Expect(svc.IsDatabaseOnline()).To(BeTrue())Expect(mock.ExpectationsWereMet()).ShouldNot(HaveOccurred())diff --git a/services/tenant.go b/service/tenant.gosimilarity index 84%rename from services/tenant.gorename to service/tenant.goindex 6fd5645f8..eee327f6c 100644--- a/services/tenant.go+++ b/service/tenant.go@@ -1,16 +1,16 @@-package services+package serviceimport ("database/sql""strings""github.com/WeCanHearYou/wchy/env"- "github.com/WeCanHearYou/wchy/models"+ "github.com/WeCanHearYou/wchy/model")// TenantService contains read and write operations for tenantstype TenantService interface {- GetByDomain(domain string) (*models.Tenant, error)+ GetByDomain(domain string) (*model.Tenant, error)}// PostgresTenantService contains read and write operations for tenants@@ -19,8 +19,8 @@ type PostgresTenantService struct {}// GetByDomain returns a tenant based on its domain-func (svc PostgresTenantService) GetByDomain(domain string) (*models.Tenant, error) {- tenant := &models.Tenant{}+func (svc PostgresTenantService) GetByDomain(domain string) (*model.Tenant, error) {+ tenant := &model.Tenant{}row := svc.DB.QueryRow("SELECT id, name, subdomain FROM tenants WHERE subdomain = $1", extractSubdomain(domain))err := row.Scan(&tenant.ID, &tenant.Name, &tenant.Domain)diff --git a/services/tenant_test.go b/service/tenant_test.gosimilarity index 88%rename from services/tenant_test.gorename to service/tenant_test.goindex c132120d4..58606c3e1 100644--- a/services/tenant_test.go+++ b/service/tenant_test.go@@ -1,12 +1,12 @@-package services_test+package service_testimport ("database/sql""testing"- "github.com/WeCanHearYou/wchy/services"sqlmock "gopkg.in/DATA-DOG/go-sqlmock.v1"+ "github.com/WeCanHearYou/wchy/service". "github.com/onsi/gomega")@@ -18,7 +18,7 @@ func TestTenantService_GetByDomain_Error(t *testing.T) {mock.ExpectQuery("SELECT id, name, subdomain FROM tenants WHERE subdomain = \\$1").WithArgs("mydomain").WillReturnError(sql.ErrNoRows)- svc := &services.PostgresTenantService{DB: db}+ svc := &service.PostgresTenantService{DB: db}tenant, err := svc.GetByDomain("mydomain")Expect(tenant).To(BeNil())@@ -34,7 +34,7 @@ func TestTenantService_GetByDomain_Subdomain(t *testing.T) {rows := sqlmock.NewRows([]string{"id", "name", "subdomain"}).AddRow(234, "My Domain Inc.", "mydomain")mock.ExpectQuery("SELECT id, name, subdomain FROM tenants WHERE subdomain = \\$1").WithArgs("mydomain").WillReturnRows(rows)- svc := &services.PostgresTenantService{DB: db}+ svc := &service.PostgresTenantService{DB: db}tenant, err := svc.GetByDomain("mydomain")Expect(tenant.ID).To(Equal(234))@@ -52,7 +52,7 @@ func TestTenantService_GetByDomain_FullDomain(t *testing.T) {rows := sqlmock.NewRows([]string{"id", "name", "subdomain"}).AddRow(234, "My Domain Inc.", "mydomain")mock.ExpectQuery("SELECT id, name, subdomain FROM tenants WHERE subdomain = \\$1").WithArgs("mydomain").WillReturnRows(rows)- svc := &services.PostgresTenantService{DB: db}+ svc := &service.PostgresTenantService{DB: db}tenant, err := svc.GetByDomain("mydomain.anydomain.com")Expect(tenant.ID).To(Equal(234))