From 3245819e2450c66a56ffbb59cc64e158c1f038a3 Mon Sep 17 00:00:00 2001 From: alexferl Date: Mon, 11 Mar 2024 13:38:18 -0400 Subject: [PATCH] move to server module --- README.md | 2 +- cmd/server/main.go | 6 +++--- handlers/auth_test.go | 8 ++++---- handlers/personal_access_token_test.go | 8 ++++---- handlers/root_test.go | 4 ++-- handlers/task_test.go | 8 ++++---- handlers/user_test.go | 8 ++++---- server.go => server/server.go | 4 ++-- 8 files changed, 24 insertions(+), 24 deletions(-) rename server.go => server/server.go (99%) diff --git a/README.md b/README.md index a233ff6..6174ccf 100644 --- a/README.md +++ b/README.md @@ -113,7 +113,7 @@ opening [assets/index.html](docs/index.html) in your web browser. ├── mappers <--- mapper layer that the services use to insert/retrieve models from the database ├── models <--- structs defining the various resources ├── openapi <--- OpenAPI schema files -├── server.go <--- glues handlers/services/mappers +├── server <--- glues handlers/services/mappers ├── services <--- service layer that interacts with the mappers ├── testing <--- testing helpers └── util <--- general helpers diff --git a/cmd/server/main.go b/cmd/server/main.go index 68ed2e0..7d88a4e 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -7,18 +7,18 @@ import ( "github.com/rs/zerolog/log" "github.com/spf13/viper" - app "github.com/alexferl/echo-boilerplate" "github.com/alexferl/echo-boilerplate/config" + "github.com/alexferl/echo-boilerplate/server" ) func main() { c := config.New() c.BindFlags() - s := app.NewServer() + s := server.New() log.Info().Msgf( - "Starting %s on %s environment listening at %s", + "Starting %s on %s environment listening at http://%s", viper.GetString(config.AppName), strings.ToUpper(viper.GetString(config.EnvName)), fmt.Sprintf("%s:%d", viper.GetString(config.HTTPBindAddress), viper.GetInt(config.HTTPBindPort)), diff --git a/handlers/auth_test.go b/handlers/auth_test.go index 41a8908..ba69db6 100644 --- a/handlers/auth_test.go +++ b/handlers/auth_test.go @@ -10,17 +10,17 @@ import ( jwtMw "github.com/alexferl/echo-jwt" "github.com/alexferl/echo-openapi" - "github.com/alexferl/golib/http/api/server" + api "github.com/alexferl/golib/http/api/server" "github.com/labstack/echo/v4" "github.com/spf13/viper" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" - app "github.com/alexferl/echo-boilerplate" "github.com/alexferl/echo-boilerplate/config" "github.com/alexferl/echo-boilerplate/handlers" "github.com/alexferl/echo-boilerplate/models" + "github.com/alexferl/echo-boilerplate/server" "github.com/alexferl/echo-boilerplate/services" "github.com/alexferl/echo-boilerplate/util/cookie" "github.com/alexferl/echo-boilerplate/util/jwt" @@ -29,14 +29,14 @@ import ( type AuthHandlerTestSuite struct { suite.Suite svc *handlers.MockUserService - server *server.Server + server *api.Server } func (s *AuthHandlerTestSuite) SetupTest() { svc := handlers.NewMockUserService(s.T()) h := handlers.NewAuthHandler(openapi.NewHandler(), svc) s.svc = svc - s.server = app.NewTestServer(h) + s.server = server.NewTestServer(h) } func TestAuthHandlerTestSuite(t *testing.T) { diff --git a/handlers/personal_access_token_test.go b/handlers/personal_access_token_test.go index eb111a6..109f4cf 100644 --- a/handlers/personal_access_token_test.go +++ b/handlers/personal_access_token_test.go @@ -10,16 +10,16 @@ import ( "time" "github.com/alexferl/echo-openapi" - "github.com/alexferl/golib/http/api/server" + api "github.com/alexferl/golib/http/api/server" "github.com/labstack/echo/v4" jwx "github.com/lestrrat-go/jwx/v2/jwt" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" - app "github.com/alexferl/echo-boilerplate" "github.com/alexferl/echo-boilerplate/handlers" "github.com/alexferl/echo-boilerplate/models" + "github.com/alexferl/echo-boilerplate/server" "github.com/alexferl/echo-boilerplate/services" "github.com/alexferl/echo-boilerplate/util/jwt" ) @@ -27,7 +27,7 @@ import ( type PersonalAccessTokenHandlerTestSuite struct { suite.Suite svc *handlers.MockPersonalAccessTokenService - server *server.Server + server *api.Server user *models.User accessToken []byte admin *models.User @@ -43,7 +43,7 @@ func (s *PersonalAccessTokenHandlerTestSuite) SetupTest() { access, _, _ := user.Login() s.svc = svc - s.server = app.NewTestServer(h) + s.server = server.NewTestServer(h) s.user = user s.accessToken = access } diff --git a/handlers/root_test.go b/handlers/root_test.go index 296b705..f5acdb9 100644 --- a/handlers/root_test.go +++ b/handlers/root_test.go @@ -8,14 +8,14 @@ import ( "github.com/alexferl/echo-openapi" "github.com/stretchr/testify/assert" - app "github.com/alexferl/echo-boilerplate" "github.com/alexferl/echo-boilerplate/handlers" + "github.com/alexferl/echo-boilerplate/server" _ "github.com/alexferl/echo-boilerplate/testing" ) func TestHandler_Root(t *testing.T) { h := handlers.NewRootHandler(openapi.NewHandler()) - s := app.NewTestServer(h) + s := server.NewTestServer(h) req := httptest.NewRequest(http.MethodGet, "/", nil) resp := httptest.NewRecorder() diff --git a/handlers/task_test.go b/handlers/task_test.go index b013601..56c9b18 100644 --- a/handlers/task_test.go +++ b/handlers/task_test.go @@ -9,23 +9,23 @@ import ( "testing" "github.com/alexferl/echo-openapi" - "github.com/alexferl/golib/http/api/server" + api "github.com/alexferl/golib/http/api/server" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" - app "github.com/alexferl/echo-boilerplate" "github.com/alexferl/echo-boilerplate/data" "github.com/alexferl/echo-boilerplate/handlers" "github.com/alexferl/echo-boilerplate/models" + "github.com/alexferl/echo-boilerplate/server" "github.com/alexferl/echo-boilerplate/services" ) type TaskHandlerTestSuite struct { suite.Suite svc *handlers.MockTaskService - server *server.Server + server *api.Server user *models.User accessToken []byte } @@ -39,7 +39,7 @@ func (s *TaskHandlerTestSuite) SetupTest() { access, _, _ := user.Login() s.svc = svc - s.server = app.NewTestServer(h) + s.server = server.NewTestServer(h) s.user = user s.accessToken = access } diff --git a/handlers/user_test.go b/handlers/user_test.go index e8b6e17..37d85b6 100644 --- a/handlers/user_test.go +++ b/handlers/user_test.go @@ -9,22 +9,22 @@ import ( "testing" "github.com/alexferl/echo-openapi" - "github.com/alexferl/golib/http/api/server" + api "github.com/alexferl/golib/http/api/server" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" - app "github.com/alexferl/echo-boilerplate" "github.com/alexferl/echo-boilerplate/handlers" "github.com/alexferl/echo-boilerplate/models" + "github.com/alexferl/echo-boilerplate/server" "github.com/alexferl/echo-boilerplate/services" ) type UserHandlerTestSuite struct { suite.Suite svc *handlers.MockUserService - server *server.Server + server *api.Server user *models.User accessToken []byte admin *models.User @@ -45,7 +45,7 @@ func (s *UserHandlerTestSuite) SetupTest() { adminAccess, _, _ := admin.Login() s.svc = svc - s.server = app.NewTestServer(h) + s.server = server.NewTestServer(h) s.user = user s.accessToken = access s.admin = admin diff --git a/server.go b/server/server.go similarity index 99% rename from server.go rename to server/server.go index 55044f7..fab225d 100644 --- a/server.go +++ b/server/server.go @@ -1,4 +1,4 @@ -package app +package server import ( "context" @@ -29,7 +29,7 @@ import ( "github.com/alexferl/echo-boilerplate/util/jwt" ) -func NewServer() *server.Server { +func New() *server.Server { client, err := data.MewMongoClient() if err != nil { log.Panic().Err(err).Msg("failed creating mongo client")