Add an example to the README

Signed-off-by: René Jochum <rene@jochum.dev>
master
René Jochum 2 years ago
parent 847b48f425
commit 7200dcdd62

@ -17,7 +17,70 @@ It looks for services that host "proto/routerclientpb/routerclientpb.RouterClien
## Examples
For now you have to look at [internalService](https://github.com/go-micro/router/blob/master/cmd/microrouterd/main.go#L20) or the author's FOSS project [microlobby](https://github.com/pcdummy/microlobby).
Have a look at [internalService](https://github.com/go-micro/router/blob/master/cmd/microrouterd/main.go#L35) or the author's FOSS project [microlobby](https://github.com/pcdummy/microlobby).
Here some code from the microlobby project
```go
import (
"github.com/go-micro/router"
"github.com/urfave/cli/v2"
"go-micro.dev/v4"
"wz2100.net/microlobby/shared/proto/authservicepb/v1"
)
func main() {
service := micro.NewService()
service.Init(
micro.Action(func(c *cli.Context) error {
s := service.Server()
r := router.NewHandler(
config.RouterURI,
router.NewRoute(
router.Method(router.MethodGet),
router.Path("/"),
router.Endpoint(authservicepb.AuthV1Service.UserList),
router.Params("limit", "offset"),
),
router.NewRoute(
router.Method(router.MethodPost),
router.Path("/login"),
router.Endpoint(authservicepb.AuthV1Service.Login),
),
router.NewRoute(
router.Method(router.MethodPost),
router.Path("/register"),
router.Endpoint(authservicepb.AuthV1Service.Register),
),
router.NewRoute(
router.Method(router.MethodPost),
router.Path("/refresh"),
router.Endpoint(authservicepb.AuthV1Service.Refresh),
),
router.NewRoute(
router.Method(router.MethodDelete),
router.Path("/:userId"),
router.Endpoint(authservicepb.AuthV1Service.UserDelete),
router.Params("userId"),
),
router.NewRoute(
router.Method(router.MethodGet),
router.Path("/:userId"),
router.Endpoint(authservicepb.AuthV1Service.UserDetail),
router.Params("userId"),
),
router.NewRoute(
router.Method(router.MethodPut),
router.Path("/:userId/roles"),
router.Endpoint(authservicepb.AuthV1Service.UserUpdateRoles),
router.Params("userId"),
),
)
r.RegisterWithServer(s)
}
)
}
```
## Build podman/docker image

Loading…
Cancel
Save