-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from cukhoaimon/feat/refactor
feat!: refactor all code base on clean architecture by Uncle Bob
- Loading branch information
Showing
112 changed files
with
806 additions
and
668 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/cukhoaimon/SimpleBank/internal/app" | ||
"github.com/cukhoaimon/SimpleBank/utils" | ||
"log" | ||
) | ||
|
||
func main() { | ||
// load config | ||
config, err := utils.LoadConfig(".") | ||
if err != nil { | ||
|
||
log.Fatal(err.Error()) | ||
} | ||
|
||
app.Run(config) | ||
} |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
This file was deleted.
Oops, something went wrong.
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,35 @@ | ||
package app | ||
|
||
import ( | ||
"database/sql" | ||
db "github.com/cukhoaimon/SimpleBank/internal/usecase/sqlc" | ||
"github.com/cukhoaimon/SimpleBank/pkg/grpc" | ||
"github.com/cukhoaimon/SimpleBank/utils" | ||
"github.com/golang-migrate/migrate/v4/database/postgres" | ||
_ "github.com/golang-migrate/migrate/v4/database/postgres" | ||
_ "github.com/golang-migrate/migrate/v4/source/file" | ||
_ "github.com/golang-migrate/migrate/v4/source/github" | ||
_ "github.com/lib/pq" | ||
"log" | ||
) | ||
|
||
// Run will run simple bank app | ||
func Run(config utils.Config) { | ||
conn, err := sql.Open(config.DBDriver, config.DBSource) | ||
if err != nil { | ||
log.Fatal("The open connection to database process was encountered an error", err) | ||
} | ||
|
||
driver, err := postgres.WithInstance(conn, &postgres.Config{}) | ||
if err != nil { | ||
log.Fatal("Error when create postgres driver instance: ", err) | ||
} | ||
|
||
RunDBMigration(config.MigrationURL, config.PostgresDB, driver) | ||
|
||
store := db.NewStore(conn) | ||
|
||
go grpc.RunGatewayServer(store, config) | ||
grpc.Run(store, config) | ||
//http2.Run(store, config) | ||
} |
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,20 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/golang-migrate/migrate/v4" | ||
"github.com/golang-migrate/migrate/v4/database" | ||
"log" | ||
) | ||
|
||
func RunDBMigration(sourceURL string, databaseName string, databaseInstance database.Driver) { | ||
migration, err := migrate.NewWithDatabaseInstance(sourceURL, databaseName, databaseInstance) | ||
if err != nil { | ||
log.Fatal("fail to create migration instance: ", err) | ||
} | ||
|
||
if err = migration.Up(); err != nil && err.Error() != "no change" { | ||
log.Fatal("fail to run migrate up: ", err) | ||
} | ||
|
||
log.Println("migration is successfully") | ||
} |
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.
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,13 @@ | ||
package gapi | ||
|
||
import ( | ||
db "github.com/cukhoaimon/SimpleBank/internal/usecase/sqlc" | ||
"github.com/cukhoaimon/SimpleBank/pkg/token" | ||
"github.com/cukhoaimon/SimpleBank/utils" | ||
) | ||
|
||
type Handler struct { | ||
Config utils.Config | ||
TokenMaker token.Maker | ||
Store db.Store | ||
} |
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
Oops, something went wrong.