-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5904fa
commit 2f97635
Showing
10 changed files
with
50 additions
and
49 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 |
---|---|---|
@@ -1,30 +1,37 @@ | ||
package middlewares | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"runtime/debug" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// ErrorHandle is a middleware to handle panic | ||
func ErrorHandle(c *gin.Context) { | ||
defer func() { | ||
if err := recover(); err != nil { | ||
// log error | ||
|
||
// print stack trace | ||
debug.PrintStack() | ||
|
||
// return error response | ||
c.JSON(http.StatusInternalServerError, gin.H{ | ||
"code": http.StatusInternalServerError, | ||
"message": "Internal Server Error", | ||
}) | ||
|
||
// abort request | ||
c.Abort() | ||
} | ||
}() | ||
c.Next() | ||
func ErrorHandle() gin.HandlerFunc { | ||
return func(c *gin.Context) { | ||
|
||
defer func() { | ||
if err := recover(); err != nil { | ||
// log error | ||
log.Println(err) | ||
|
||
// print stack trace | ||
debug.PrintStack() | ||
|
||
// return error response | ||
c.JSON(http.StatusInternalServerError, gin.H{ | ||
"code": http.StatusInternalServerError, | ||
"message": "Internal Server Error", | ||
}) | ||
|
||
// abort request | ||
c.Abort() | ||
} | ||
}() | ||
|
||
c.Next() | ||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -36,7 +36,6 @@ func Jwt() gin.HandlerFunc { | |
} | ||
|
||
ctx.Next() | ||
|
||
} | ||
|
||
} |
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 |
---|---|---|
|
@@ -11,6 +11,7 @@ var ( | |
|
||
LogrusLogger *logrus.Logger | ||
|
||
// export Logger | ||
Logger *logrus.Logger | ||
) | ||
|
||
|
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 routes | ||
package router | ||
|
||
import ( | ||
"go-gin-boilerplate/internal/controllers" | ||
|
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 routes | ||
package router | ||
|
||
import ( | ||
"go-gin-boilerplate/internal/controllers" | ||
|
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package routes | ||
package router | ||
|
||
import ( | ||
"go-gin-boilerplate/internal/controllers" | ||
|