go-template/app/api/example_api/example_api.go

25 lines
556 B
Go
Raw Normal View History

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"
2021-12-31 00:47:27 +08:00
"git.icechen.cn/${REPO_OWNER}/${REPO_NAME}/pkg/proto/example_service"
"git.icechen.cn/${REPO_OWNER}/${REPO_NAME}/pkg/rpc"
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-30 01:16:32 +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
}