A ready-to-use and simple go-micro router
You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Go to file
René Jochum 211adc4a77 Move to jochum.dev
Signed-off-by: René Jochum <rene@jochum.dev>
2 years ago
cmd/microrouterd Move to jochum.dev 2 years ago
docker Move to jochum.dev 2 years ago
internal Move to jochum.dev 2 years ago
.gitignore Rename ServerConfig->RouterConfig, smaller build fixes 2 years ago
LICENSE.spdx Move to jochum.dev 2 years ago
README.md Move to jochum.dev 2 years ago
Taskfile.yml Switch to registry.fk.jochum.dev 2 years ago
go.mod Move to jochum.dev 2 years ago
go.sum Run of go mod tidy 2 years ago
handler.go Move to jochum.dev 2 years ago
method.go Make none client code internal, redesign the api. 2 years ago
route.go Make none client code internal, redesign the api. 2 years ago

README.md

router

A dynamic router (API Gatway) for go-micro.

It looks for services that host "proto/routerclientpb/routerclientpb.RouterClientService" and ask's them for routes/endpoints, then it registers that endpoints via a proxy method within gin.

Caveats

  • gin doesn't allow to delete routes, so if you want to delete a route you have to restart go-micro/router.

Todo

  • Add (more) examples.
  • Add support for Streams / WebSockets.
  • Add support for debug.
  • Maybe add optional support for auth.

Examples

Have a look at internalService or the author's FOSS project microlobby.

Here's some code from the microlobby project

import (
	"jochum.dev/jo-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)
		}
	)
}

Developers corner

Build podman/docker image

Prerequesits

Build

task

Remove everything except the resulting podman images created by task

task rm

Authors

License

Its dual licensed:

  • Apache-2.0
  • GPL-2.0-or-later