Skip to content

Commit

Permalink
Merge pull request #12 from bmf-san/fix/logger-interface
Browse files Browse the repository at this point in the history
Move Logger interface from usecases to interfaces
  • Loading branch information
bmf-san authored Apr 6, 2022
2 parents c268c70 + e4c027a commit 034d0af
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/infrastructure/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions app/infrastructure/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}

Expand Down
3 changes: 1 addition & 2 deletions app/infrastructure/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion app/usecases/logger.go → app/interfaces/logger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package usecases
package interfaces

// A Logger belong to the usecases layer.
type Logger interface {
Expand Down
4 changes: 2 additions & 2 deletions app/interfaces/post_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions app/interfaces/user_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 034d0af

Please sign in to comment.