From 567ff27eff1addffdfa1228d8d3b8ce2a465c95d Mon Sep 17 00:00:00 2001 From: Tt yo Date: Fri, 9 Jul 2021 21:53:21 +0800 Subject: [PATCH] examples: add echo example (#1162) * examples: add echo examples * style: update code style. --- examples/http/echo/main.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 examples/http/echo/main.go diff --git a/examples/http/echo/main.go b/examples/http/echo/main.go new file mode 100644 index 000000000..442645fdf --- /dev/null +++ b/examples/http/echo/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "github.com/go-kratos/kratos/v2" + "github.com/go-kratos/kratos/v2/transport/http" + "github.com/labstack/echo/v4" + "log" +) + +func main() { + router := echo.New() + router.GET("/home", func(ctx echo.Context) error { + return ctx.JSON(200,"Hello echo") + }) + + httpSrv := http.NewServer(http.Address(":8000")) + httpSrv.HandlePrefix("/", router) + + app := kratos.New( + kratos.Name("echo"), + kratos.Server( + httpSrv, + ), + ) + if err := app.Run(); err != nil { + log.Fatal(err) + } +} \ No newline at end of file