mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-17 21:07:54 +02:00
examples: add echo example (#1162)
* examples: add echo examples * style: update code style.
This commit is contained in:
parent
ac8c27ff9f
commit
567ff27eff
28
examples/http/echo/main.go
Normal file
28
examples/http/echo/main.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user