-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ supporting Inbox and Outbox Pattern
- Loading branch information
1 parent
dfa600b
commit dfa0d50
Showing
46 changed files
with
605 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package environment | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/mehdihadeli/go-ecommerce-microservices/internal/pkg/constants" | ||
|
||
"emperror.dev/errors" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func FixProjectRootWorkingDirectoryPath() { | ||
currentWD, _ := os.Getwd() | ||
log.Printf("Current working directory is: `%s`", currentWD) | ||
|
||
rootDir := GetProjectRootWorkingDirectory() | ||
// change working directory | ||
_ = os.Chdir(rootDir) | ||
newWD, _ := os.Getwd() | ||
|
||
log.Printf("New fixed working directory is: `%s`", newWD) | ||
} | ||
|
||
func GetProjectRootWorkingDirectory() string { | ||
var rootWorkingDirectory string | ||
// https://articles.wesionary.team/environment-variable-configuration-in-your-golang-project-using-viper-4e8289ef664d | ||
// when we `Set` a viper with string value, we should get it from viper with `viper.GetString`, elsewhere we get empty string | ||
// viper will get it from `os env` or a .env file | ||
pn := viper.GetString(constants.PROJECT_NAME_ENV) | ||
if pn != "" { | ||
rootWorkingDirectory = getProjectRootDirectoryFromProjectName(pn) | ||
} else { | ||
wd, _ := os.Getwd() | ||
dir, err := searchRootDirectory(wd) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
rootWorkingDirectory = dir | ||
} | ||
|
||
absoluteRootWorkingDirectory, _ := filepath.Abs(rootWorkingDirectory) | ||
|
||
return absoluteRootWorkingDirectory | ||
} | ||
|
||
func getProjectRootDirectoryFromProjectName(pn string) string { | ||
// set root working directory of our app in the viper | ||
// https://stackoverflow.com/a/47785436/581476 | ||
wd, _ := os.Getwd() | ||
|
||
for !strings.HasSuffix(wd, pn) { | ||
wd = filepath.Dir(wd) | ||
} | ||
|
||
return wd | ||
} | ||
|
||
func searchRootDirectory( | ||
dir string, | ||
) (string, error) { | ||
// List files and directories in the current directory | ||
files, err := os.ReadDir(dir) | ||
if err != nil { | ||
return "", errors.WrapIf(err, "Error reading directory") | ||
} | ||
|
||
for _, file := range files { | ||
if !file.IsDir() { | ||
fileName := file.Name() | ||
if strings.EqualFold( | ||
fileName, | ||
"go.mod", | ||
) { | ||
return dir, nil | ||
} | ||
} | ||
} | ||
|
||
// If no config file found in this directory, recursively search its parent | ||
parentDir := filepath.Dir(dir) | ||
if parentDir == dir { | ||
// We've reached the root directory, and no go.mod file was found | ||
return "", errors.WrapIf(err, "No go.mod file found") | ||
} | ||
|
||
return searchRootDirectory(parentDir) | ||
} |
14 changes: 9 additions & 5 deletions
14
internal/pkg/core/messaging/persistmessage/message_persistence_repository.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
package persistmessage | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
|
||
uuid "github.com/satori/go.uuid" | ||
) | ||
|
||
type MessagePersistenceRepository interface { | ||
Add(ctx context.Context, storeMessage *StoreMessage) error | ||
Update(ctx context.Context, storeMessage *StoreMessage) error | ||
ChangeState( | ||
ctx context.Context, | ||
messageID string, | ||
messageID uuid.UUID, | ||
status MessageStatus, | ||
) error | ||
GetAll(ctx context.Context) ([]*StoreMessage, error) | ||
GetAllActive(ctx context.Context) ([]*StoreMessage, error) | ||
GetByFilter( | ||
ctx context.Context, | ||
predicate func(*StoreMessage) bool, | ||
) ([]*StoreMessage, error) | ||
GetById(ctx context.Context, id string) (*StoreMessage, error) | ||
GetById(ctx context.Context, id uuid.UUID) (*StoreMessage, error) | ||
Remove(ctx context.Context, storeMessage *StoreMessage) (bool, error) | ||
CleanupMessages() | ||
CleanupMessages(ctx context.Context) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
internal/pkg/postgresGorm/gorm_options.go → internal/pkg/postgresgorm/gorm_options.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package postgresGorm | ||
package postgresgorm | ||
|
||
import ( | ||
"fmt" | ||
|
2 changes: 1 addition & 1 deletion
2
...nal/pkg/postgresGorm/gorm_options_test.go → ...nal/pkg/postgresgorm/gorm_options_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package postgresGorm | ||
package postgresgorm | ||
|
||
import ( | ||
"testing" | ||
|
2 changes: 1 addition & 1 deletion
2
...rnal/pkg/postgresGorm/gorm_postgres_fx.go → ...rnal/pkg/postgresgorm/gorm_postgres_fx.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package postgresGorm | ||
package postgresgorm | ||
|
||
import ( | ||
"fmt" | ||
|
2 changes: 1 addition & 1 deletion
2
internal/pkg/postgresGorm/health.go → internal/pkg/postgresgorm/health.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package postgresGorm | ||
package postgresgorm | ||
|
||
import ( | ||
"context" | ||
|
2 changes: 1 addition & 1 deletion
2
internal/pkg/postgresGorm/helpers.go → internal/pkg/postgresgorm/helpers.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package postgresGorm | ||
package postgresgorm | ||
|
||
import ( | ||
"context" | ||
|
Oops, something went wrong.