From e4c027ab3ad14f8981e556e4a7c4842a4f13a0f5 Mon Sep 17 00:00:00 2001 From: bmf-san Date: Wed, 6 Apr 2022 23:20:47 +0900 Subject: [PATCH] [update] move Logger interface from usecases to interfaces --- app/infrastructure/env.go | 4 ++-- app/infrastructure/logger.go | 4 +--- app/infrastructure/router.go | 3 +-- app/{usecases => interfaces}/logger.go | 2 +- app/interfaces/post_controller.go | 4 ++-- app/interfaces/user_controller.go | 4 ++-- 6 files changed, 9 insertions(+), 12 deletions(-) rename app/{usecases => interfaces}/logger.go (87%) diff --git a/app/infrastructure/env.go b/app/infrastructure/env.go index 137211e..2d416f8 100644 --- a/app/infrastructure/env.go +++ b/app/infrastructure/env.go @@ -5,11 +5,11 @@ import ( "os" "strings" - "github.com/bmf-san/go-clean-architecture-web-application-boilerplate/app/usecases" + "github.com/bmf-san/go-clean-architecture-web-application-boilerplate/app/interfaces" ) // Load is load configs from a env file. -func Load(logger usecases.Logger) { +func Load(logger interfaces.Logger) { filePath := ".env" f, err := os.Open(filePath) diff --git a/app/infrastructure/logger.go b/app/infrastructure/logger.go index bce4608..ac7c792 100644 --- a/app/infrastructure/logger.go +++ b/app/infrastructure/logger.go @@ -4,15 +4,13 @@ import ( "io" "log" "os" - - "github.com/bmf-san/go-clean-architecture-web-application-boilerplate/app/usecases" ) // A Logger belong to the infrastructure layer. type Logger struct{} // NewLogger return a Logger. -func NewLogger() usecases.Logger { +func NewLogger() *Logger { return &Logger{} } diff --git a/app/infrastructure/router.go b/app/infrastructure/router.go index 1bf8dc3..9d0e491 100644 --- a/app/infrastructure/router.go +++ b/app/infrastructure/router.go @@ -5,12 +5,11 @@ import ( "os" "github.com/bmf-san/go-clean-architecture-web-application-boilerplate/app/interfaces" - "github.com/bmf-san/go-clean-architecture-web-application-boilerplate/app/usecases" "github.com/go-chi/chi" ) // Dispatch is handle routing -func Dispatch(logger usecases.Logger, sqlHandler interfaces.SQLHandler) { +func Dispatch(logger interfaces.Logger, sqlHandler interfaces.SQLHandler) { userController := interfaces.NewUserController(sqlHandler, logger) postController := interfaces.NewPostController(sqlHandler, logger) diff --git a/app/usecases/logger.go b/app/interfaces/logger.go similarity index 87% rename from app/usecases/logger.go rename to app/interfaces/logger.go index a7fc9e7..8c5a1f0 100644 --- a/app/usecases/logger.go +++ b/app/interfaces/logger.go @@ -1,4 +1,4 @@ -package usecases +package interfaces // A Logger belong to the usecases layer. type Logger interface { diff --git a/app/interfaces/post_controller.go b/app/interfaces/post_controller.go index 0244a71..48affbf 100644 --- a/app/interfaces/post_controller.go +++ b/app/interfaces/post_controller.go @@ -12,11 +12,11 @@ import ( // A PostController belong to the interface layer. type PostController struct { PostInteractor usecases.PostInteractor - Logger usecases.Logger + Logger Logger } // NewPostController returns the resource of Posts. -func NewPostController(sqlHandler SQLHandler, logger usecases.Logger) *PostController { +func NewPostController(sqlHandler SQLHandler, logger Logger) *PostController { return &PostController{ PostInteractor: usecases.PostInteractor{ PostRepository: &PostRepository{ diff --git a/app/interfaces/user_controller.go b/app/interfaces/user_controller.go index f487cbd..3f7d556 100644 --- a/app/interfaces/user_controller.go +++ b/app/interfaces/user_controller.go @@ -11,11 +11,11 @@ import ( // A UserController belong to the interface layer. type UserController struct { UserInteractor usecases.UserInteractor - Logger usecases.Logger + Logger Logger } // NewUserController returns the resource of users. -func NewUserController(sqlHandler SQLHandler, logger usecases.Logger) *UserController { +func NewUserController(sqlHandler SQLHandler, logger Logger) *UserController { return &UserController{ UserInteractor: usecases.UserInteractor{ UserRepository: &UserRepository{