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 1daaebdacd
Fix drone CI
2 years ago
cmd/microrouterd Protect :8080/router/routes with endpointroles 2 years ago
docker/router Make docker registry configureable 2 years ago
internal Rename internal/logger to internal/ilogger 2 years ago
.drone.yml Fix drone CI 2 years ago
.env.sample Make docker registry configureable 2 years ago
.gitignore Make docker registry configureable 2 years ago
LICENSE Fix the LICENSE 2 years ago
README.md Update README version 2 years ago
Taskfile.yml Protect :8080/router/routes with endpointroles 2 years ago
go.mod jo-micro/auth2@v0.0.2 2 years ago
go.sum jo-micro/auth2@v0.0.2 2 years ago
handler.go Add auth support 2 years ago
method.go Fix routes having the same method, update docs, update build 2 years ago
route.go Add auth support 2 years ago

README.md

Build Status Go Reference

router

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

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

AUTH is WORK IN PROGRESS

I'm still working on the implementation of jo-micro/auth2, everything Auth related my change.

Caveats

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

Usage

docker-compose without auth

docker-compose:

services:
  router:
    restart: unless-stopped
    image: docker.io/jomicro/router:0.3.1
    environment:
      - MICRO_TRANSPORT=grpc
      - MICRO_REGISTRY=nats
      - MICRO_REGISTRY_ADDRESS=nats:4222
      - MICRO_BROKER=nats
      - MICRO_BROKER_ADDRESS=nats:4222
      - MICRO_ROUTER_LISTEN=:8080
      - MICRO_ROUTER_LOG_LEVEL=info

    ports:
      - 8080:8080
    depends_on:
      - nats

docker-compose with auth

services:
  router:
    restart: unless-stopped
    image: docker.io/jomicro/router:0.3.1
    environment:
      - MICRO_AUTH2_CLIENT=jwt
      - MICRO_AUTH2_ROUTER=jwt
      - MICRO_AUTH2_JWT_AUDIENCES="key from task keys inside the auth project"
      - MICRO_AUTH2_JWT_PRIV_KEY="key from task keys inside the auth project"
      - MICRO_AUTH2_JWT_PUB_KEY="key from task keys inside the auth project"
      - MICRO_TRANSPORT=grpc
      - MICRO_REGISTRY=nats
      - MICRO_REGISTRY_ADDRESS=nats:4222
      - MICRO_BROKER=nats
      - MICRO_BROKER_ADDRESS=nats:4222
      - MICRO_ROUTER_LISTEN=:8080
      - MICRO_ROUTER_LOG_LEVEL=info

    ports:
      - 8080:8080
    depends_on:
      - nats

See cmd/microrouterd/plugins.go for a list of availabel transports, registries and brokers.

Todo

  • Add support for Streams / WebSockets.
  • Add support for debug?

Service integration 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.AuthRequired(),
                ),
                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.AuthRequired(),
                ),
                router.NewRoute(
                    router.Method(router.MethodGet),
                    router.Path("/:userId"),
                    router.Endpoint(authservicepb.AuthV1Service.UserDetail),
                    router.Params("userId"),
                    router.AuthRequired(),
                ),
                router.NewRoute(
                    router.Method(router.MethodPut),
                    router.Path("/:userId/roles"),
                    router.Endpoint(authservicepb.AuthV1Service.UserUpdateRoles),
                    router.Params("userId"),
                    router.AuthRequired(),
                ),
            )
            r.RegisterWithServer(s)
        }
    )
}

Developers corner

Build podman/docker image

Prerequesits

Build

cp .env.sample .env
task

Remove everything

task rm

Authors

License

Its dual licensed:

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