Skip to content

Commit

Permalink
feat: add debug print (#29)
Browse files Browse the repository at this point in the history
* feat: add debug print

* workflow: fallback codecov to v3
  • Loading branch information
devhaozi authored Sep 18, 2023
1 parent 6f90a8f commit 56b8cb1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Run tests with coverage
run: go test -v -coverprofile="coverage.out" ./...
- name: Upload coverage report to Codecov
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v3
with:
file: ./coverage.out
token: ${{ secrets.CODECOV }}
2 changes: 1 addition & 1 deletion context_response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestResponse(t *testing.T) {
method: "GET",
url: "/origin",
setup: func(method, url string) error {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
mockConfig.On("Get", "cors.allowed_methods").Return([]string{"*"}).Once()
Expand Down
16 changes: 8 additions & 8 deletions cors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestCors(t *testing.T) {
{
name: "allow all paths",
setup: func() {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
Expand All @@ -49,7 +49,7 @@ func TestCors(t *testing.T) {
{
name: "not allow path",
setup: func() {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once()
mockConfig.On("Get", "cors.paths").Return([]string{"api"}).Once()
Expand All @@ -66,7 +66,7 @@ func TestCors(t *testing.T) {
{
name: "allow path with *",
setup: func() {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once()
mockConfig.On("Get", "cors.paths").Return([]string{"any/*"}).Once()
Expand All @@ -89,7 +89,7 @@ func TestCors(t *testing.T) {
{
name: "only allow POST",
setup: func() {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
Expand All @@ -112,7 +112,7 @@ func TestCors(t *testing.T) {
{
name: "not allow POST",
setup: func() {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
Expand All @@ -135,7 +135,7 @@ func TestCors(t *testing.T) {
{
name: "not allow origin",
setup: func() {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
Expand All @@ -158,7 +158,7 @@ func TestCors(t *testing.T) {
{
name: "allow specific origin",
setup: func() {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
Expand All @@ -181,7 +181,7 @@ func TestCors(t *testing.T) {
{
name: "not allow exposed headers",
setup: func() {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("GetBool", "http.drivers.fiber.prefork", false).Return(false).Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
Expand Down
14 changes: 7 additions & 7 deletions group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func TestGroup(t *testing.T) {
{
name: "Resource Index",
setup: func(req *http.Request) {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
mockConfig.On("Get", "cors.allowed_methods").Return([]string{"*"}).Once()
Expand All @@ -259,7 +259,7 @@ func TestGroup(t *testing.T) {
{
name: "Resource Show",
setup: func(req *http.Request) {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
mockConfig.On("Get", "cors.allowed_methods").Return([]string{"*"}).Once()
Expand All @@ -284,7 +284,7 @@ func TestGroup(t *testing.T) {
{
name: "Resource Store",
setup: func(req *http.Request) {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
mockConfig.On("Get", "cors.allowed_methods").Return([]string{"*"}).Once()
Expand All @@ -309,7 +309,7 @@ func TestGroup(t *testing.T) {
{
name: "Resource Update (PUT)",
setup: func(req *http.Request) {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
mockConfig.On("Get", "cors.allowed_methods").Return([]string{"*"}).Once()
Expand All @@ -334,7 +334,7 @@ func TestGroup(t *testing.T) {
{
name: "Resource Update (PATCH)",
setup: func(req *http.Request) {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
mockConfig.On("Get", "cors.allowed_methods").Return([]string{"*"}).Once()
Expand All @@ -359,7 +359,7 @@ func TestGroup(t *testing.T) {
{
name: "Resource Destroy",
setup: func(req *http.Request) {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
mockConfig.On("Get", "cors.allowed_methods").Return([]string{"*"}).Once()
Expand Down Expand Up @@ -508,7 +508,7 @@ func TestGroup(t *testing.T) {
{
name: "Global Middleware",
setup: func(req *http.Request) {
mockConfig.On("GetBool", "app.debug", false).Return(true).Once()
mockConfig.On("GetBool", "app.debug", false).Return(true).Twice()
mockConfig.On("GetString", "app.timezone", "UTC").Return("UTC").Once()
mockConfig.On("Get", "cors.paths").Return([]string{"*"}).Once()
mockConfig.On("Get", "cors.allowed_methods").Return([]string{"*"}).Once()
Expand Down
4 changes: 3 additions & 1 deletion route.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ func (r *Route) Fallback(handler httpcontract.HandlerFunc) {
// GlobalMiddleware 设置全局中间件
func (r *Route) GlobalMiddleware(middlewares ...httpcontract.Middleware) {
middlewares = append(middlewares, Cors())
tempMiddlewares := []any{recover.New()}
tempMiddlewares := []any{recover.New(recover.Config{
EnableStackTrace: r.config.GetBool("app.debug", false),
})}
if r.config.GetBool("app.debug", false) {
tempMiddlewares = append(tempMiddlewares, logger.New(logger.Config{
Format: "[HTTP] ${time} | ${status} | ${latency} | ${ip} | ${method} | ${path}\n",
Expand Down

0 comments on commit 56b8cb1

Please sign in to comment.