refactor registry awareness logic
This commit is contained in:
@@ -0,0 +1,35 @@
|
|||||||
|
package registry
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
etcdr "github.com/micro/go-micro/v2/registry/etcd"
|
||||||
|
mdnsr "github.com/micro/go-micro/v2/registry/mdns"
|
||||||
|
|
||||||
|
"github.com/micro/go-micro/v2/registry"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
registryEnv = "MICRO_REGISTRY"
|
||||||
|
registryAddressEnv = "MICRO_REGISTRY_ADDRESS"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetRegistry returns a configured micro registry based on Micro env vars.
|
||||||
|
// It defaults to mDNS, so mind that systems with mDNS disabled by default (i.e SUSE) will have a hard time
|
||||||
|
// and it needs to explicitly use etcd. Os awareness for providing a working registry out of the box should be done.
|
||||||
|
func GetRegistry() *registry.Registry {
|
||||||
|
addresses := strings.Split(os.Getenv(registryAddressEnv), ",")
|
||||||
|
|
||||||
|
var r registry.Registry
|
||||||
|
switch os.Getenv(registryEnv) {
|
||||||
|
case "etcd":
|
||||||
|
r = etcdr.NewRegistry(
|
||||||
|
registry.Addrs(addresses...),
|
||||||
|
)
|
||||||
|
default:
|
||||||
|
r = mdnsr.NewRegistry()
|
||||||
|
}
|
||||||
|
|
||||||
|
return &r
|
||||||
|
}
|
||||||
@@ -4,14 +4,11 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
etcdr "github.com/micro/go-micro/v2/registry/etcd"
|
|
||||||
mdnsr "github.com/micro/go-micro/v2/registry/mdns"
|
|
||||||
|
|
||||||
"github.com/micro/go-micro/v2"
|
"github.com/micro/go-micro/v2"
|
||||||
"github.com/micro/go-micro/v2/registry"
|
|
||||||
|
|
||||||
"github.com/micro/cli/v2"
|
"github.com/micro/cli/v2"
|
||||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||||
|
oregistry "github.com/owncloud/ocis/ocis-pkg/registry"
|
||||||
"github.com/owncloud/ocis/ocis/pkg/config"
|
"github.com/owncloud/ocis/ocis/pkg/config"
|
||||||
"github.com/owncloud/ocis/ocis/pkg/flagset"
|
"github.com/owncloud/ocis/ocis/pkg/flagset"
|
||||||
"github.com/owncloud/ocis/ocis/pkg/register"
|
"github.com/owncloud/ocis/ocis/pkg/register"
|
||||||
@@ -50,15 +47,7 @@ func Execute() error {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
addresses := strings.Split(os.Getenv("MICRO_REGISTRY_ADDRESS"), ",")
|
r := *oregistry.GetRegistry()
|
||||||
|
|
||||||
var r registry.Registry
|
|
||||||
switch os.Getenv("MICRO_REGISTRY") {
|
|
||||||
case "etcd":
|
|
||||||
r = etcdr.NewRegistry(registry.Addrs(addresses...))
|
|
||||||
default:
|
|
||||||
r = mdnsr.NewRegistry()
|
|
||||||
}
|
|
||||||
|
|
||||||
opts := micro.Options{
|
opts := micro.Options{
|
||||||
Registry: r,
|
Registry: r,
|
||||||
|
|||||||
+2
-14
@@ -2,16 +2,12 @@ package external
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
etcdr "github.com/micro/go-micro/v2/registry/etcd"
|
|
||||||
mdnsr "github.com/micro/go-micro/v2/registry/mdns"
|
|
||||||
|
|
||||||
"github.com/micro/go-micro/v2/broker"
|
"github.com/micro/go-micro/v2/broker"
|
||||||
"github.com/micro/go-micro/v2/registry"
|
"github.com/micro/go-micro/v2/registry"
|
||||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||||
|
oregistry "github.com/owncloud/ocis/ocis-pkg/registry"
|
||||||
)
|
)
|
||||||
|
|
||||||
// RegisterGRPCEndpoint publishes an arbitrary endpoint to the service-registry. This allows to query nodes of
|
// RegisterGRPCEndpoint publishes an arbitrary endpoint to the service-registry. This allows to query nodes of
|
||||||
@@ -29,15 +25,7 @@ func RegisterGRPCEndpoint(ctx context.Context, serviceID, uuid, addr string, log
|
|||||||
node.Metadata["transport"] = "grpc"
|
node.Metadata["transport"] = "grpc"
|
||||||
node.Metadata["protocol"] = "grpc"
|
node.Metadata["protocol"] = "grpc"
|
||||||
|
|
||||||
addresses := strings.Split(os.Getenv("MICRO_REGISTRY_ADDRESS"), ",")
|
r := *oregistry.GetRegistry()
|
||||||
var r registry.Registry
|
|
||||||
|
|
||||||
switch os.Getenv("MICRO_REGISTRY") {
|
|
||||||
case "etcd":
|
|
||||||
r = etcdr.NewRegistry(registry.Addrs(addresses...))
|
|
||||||
default:
|
|
||||||
r = mdnsr.NewRegistry()
|
|
||||||
}
|
|
||||||
|
|
||||||
service := ®istry.Service{
|
service := ®istry.Service{
|
||||||
Name: serviceID,
|
Name: serviceID,
|
||||||
|
|||||||
Reference in New Issue
Block a user