2021-12-24 18:50:43 +08:00
|
|
|
package main
|
|
|
|
|
2021-12-27 21:02:11 +08:00
|
|
|
import (
|
2021-12-29 20:32:45 +08:00
|
|
|
"context"
|
|
|
|
"git.icechen.cn/pkg/go-template/pkg/proto/example_service"
|
|
|
|
"git.icechen.cn/pkg/go-template/pkg/rpc"
|
2021-12-27 21:02:11 +08:00
|
|
|
"github.com/gofiber/fiber/v2"
|
2021-12-29 20:32:45 +08:00
|
|
|
"google.golang.org/protobuf/types/known/emptypb"
|
2021-12-27 21:02:11 +08:00
|
|
|
)
|
2021-12-24 18:50:43 +08:00
|
|
|
|
|
|
|
func main() {
|
2021-12-27 21:02:11 +08:00
|
|
|
app := fiber.New()
|
|
|
|
app.Get("/test", func(c *fiber.Ctx) error {
|
2021-12-29 20:32:45 +08:00
|
|
|
userInfo, err := example_service.NewUserClient(rpc.GetServiceConn("example_service")).SayHello(context.TODO(), &emptypb.Empty{})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-12-29 20:52:36 +08:00
|
|
|
return c.JSON(userInfo.Name)
|
2021-12-27 21:02:11 +08:00
|
|
|
})
|
|
|
|
err := app.Listen(":8080")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-12-24 18:50:43 +08:00
|
|
|
}
|