Skip to content

Commit

Permalink
improve example
Browse files Browse the repository at this point in the history
  • Loading branch information
pilinux committed Dec 4, 2023
1 parent 1d5a9a7 commit 67dfa2a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 3 additions & 3 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func main() {
// read configs
configure := gconfig.GetConfig()

if configure.Database.RDBMS.Activate == gconfig.Activated {
if gconfig.IsRDBMS() {
// Initialize RDBMS client
if err := gdatabase.InitDB().Error; err != nil {
fmt.Println(err)
Expand Down Expand Up @@ -50,15 +50,15 @@ func main() {
}
}

if configure.Database.REDIS.Activate == gconfig.Activated {
if gconfig.IsRedis() {
// Initialize REDIS client
if _, err := gdatabase.InitRedis(); err != nil {
fmt.Println(err)
return
}
}

if configure.Database.MongoDB.Activate == gconfig.Activated {
if gconfig.IsMongo() {
// Initialize MONGO client
if _, err := gdatabase.InitMongo(); err != nil {
fmt.Println(err)
Expand Down
15 changes: 7 additions & 8 deletions example/router/setupRouter.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func SetupRouter(configure *gconfig.Configuration) (*gin.Engine, error) {
v1.POST("register", gcontroller.CreateUserAuth)

// Verify email
if configure.Security.VerifyEmail {
if gconfig.IsEmailVerificationService() {
if gconfig.IsRedis() {
v1.POST("verify", gcontroller.VerifyEmail)
v1.POST("resend-verification-email", gcontroller.CreateVerificationEmail)
Expand Down Expand Up @@ -159,13 +159,12 @@ func SetupRouter(configure *gconfig.Configuration) (*gin.Engine, error) {
r2FA.POST("activate", gcontroller.Activate2FA)
r2FA.POST("validate", gcontroller.Validate2FA)
r2FA.POST("validate-backup-code", gcontroller.ValidateBackup2FA)
if gconfig.Is2FA() {
r2FA.Use(gmiddleware.TwoFA(
configure.Security.TwoFA.Status.On,
configure.Security.TwoFA.Status.Off,
configure.Security.TwoFA.Status.Verified,
))
}

r2FA.Use(gmiddleware.TwoFA(
configure.Security.TwoFA.Status.On,
configure.Security.TwoFA.Status.Off,
configure.Security.TwoFA.Status.Verified,
))
// get 2FA backup codes
r2FA.POST("create-backup-codes", gcontroller.CreateBackup2FA)
// disable 2FA
Expand Down

0 comments on commit 67dfa2a

Please sign in to comment.