-
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.
feat(gctx): gctx support append domain
- Loading branch information
1 parent
b9ca0e0
commit 404b1fc
Showing
4 changed files
with
105 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/cutedogspark/echo-custom-context" | ||
"github.com/labstack/echo" | ||
"net/http" | ||
) | ||
|
||
func main() { | ||
|
||
// Echo instance | ||
e := echo.New() | ||
e.HideBanner = true | ||
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc { | ||
return func(c echo.Context) error { | ||
return next(ctx.CustomCtx{c}) | ||
} | ||
}) | ||
|
||
e.GET("/", func(c echo.Context) error { | ||
return c.(ctx.CustomCtx).GResp(http.StatusOK).Data("Service").Do() | ||
}) | ||
|
||
e.GET("/error", func(c echo.Context) error { | ||
return c.(ctx.CustomCtx).GResp().Errors(&ctx.GError{ | ||
Code: 40001002, | ||
Reason: "ParameterInvalid", | ||
Domain: "error", | ||
Message: "parameter required : id", | ||
Location: "id", | ||
LocationType: "parameter", | ||
}).Do() | ||
}) | ||
|
||
e.GET("/errors", func(c echo.Context) error { | ||
|
||
ctxErr := ctx.NewGErrors().Append(&ctx.GError{ | ||
Code: 40001003, | ||
Reason: "ParameterInvalid", | ||
Domain: "validate", | ||
Message: "parameter required : id", | ||
Location: "id", | ||
LocationType: "parameter", | ||
}).Append(&ctx.GError{ | ||
Code: 40001004, | ||
Reason: "RecordNotFound", | ||
Domain: "repository", | ||
Message: "record not found : id", | ||
Location: "id", | ||
LocationType: "user", | ||
}) | ||
|
||
ctxErr.AppendDomain("handler") | ||
|
||
return c.(ctx.CustomCtx).GResp().Errors(*ctxErr...).Do() | ||
}) | ||
|
||
// Start server | ||
e.Logger.Fatal(e.Start(":1323")) | ||
|
||
} |
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