Skip to content

Commit

Permalink
Merge pull request #17 from alexferl/server_module
Browse files Browse the repository at this point in the history
move to server module
  • Loading branch information
alexferl authored Mar 11, 2024
2 parents fa159ec + 3245819 commit d536738
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
8 changes: 4 additions & 4 deletions handlers/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions handlers/personal_access_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ 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"
)

type PersonalAccessTokenHandlerTestSuite struct {
suite.Suite
svc *handlers.MockPersonalAccessTokenService
server *server.Server
server *api.Server
user *models.User
accessToken []byte
admin *models.User
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions handlers/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions handlers/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions handlers/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server.go → server/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package app
package server

import (
"context"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit d536738

Please sign in to comment.