micro: rewrite options to support multiple building blocks

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-01-29 13:17:32 +03:00
parent ac8a3a12c4
commit 827d467077
57 changed files with 1283 additions and 644 deletions

View File

@@ -6,7 +6,7 @@ import (
"strings"
"github.com/unistack-org/micro/v3/metadata"
"github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/register"
"github.com/unistack-org/micro/v3/server"
)
@@ -56,7 +56,7 @@ type Service struct {
// The endpoint for this service
Endpoint *Endpoint
// Versions of this service
Services []*registry.Service
Services []*register.Service
}
func strip(s string) string {

View File

@@ -11,7 +11,7 @@ import (
"github.com/unistack-org/micro/v3/api"
"github.com/unistack-org/micro/v3/api/handler"
"github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/register"
)
const (
@@ -70,7 +70,7 @@ func (h *httpHandler) getService(r *http.Request) (string, error) {
}
// get the nodes for this service
nodes := make([]*registry.Node, 0, len(service.Services))
nodes := make([]*register.Node, 0, len(service.Services))
for _, srv := range service.Services {
nodes = append(nodes, srv.Nodes...)
}

View File

@@ -12,13 +12,13 @@ import (
"github.com/unistack-org/micro/v3/api/resolver"
"github.com/unistack-org/micro/v3/api/resolver/vpath"
"github.com/unistack-org/micro/v3/api/router"
regRouter "github.com/unistack-org/micro/v3/api/router/registry"
"github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/registry/memory"
regRouter "github.com/unistack-org/micro/v3/api/router/register"
"github.com/unistack-org/micro/v3/register"
"github.com/unistack-org/micro/v3/register/memory"
)
func testHttp(t *testing.T, path, service, ns string) {
r := memory.NewRegistry()
r := memory.NewRegister()
l, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
@@ -26,9 +26,9 @@ func testHttp(t *testing.T, path, service, ns string) {
}
defer l.Close()
s := &registry.Service{
s := &register.Service{
Name: service,
Nodes: []*registry.Node{
Nodes: []*register.Node{
{
Id: service + "-1",
Address: l.Addr().String(),
@@ -58,7 +58,7 @@ func testHttp(t *testing.T, path, service, ns string) {
// initialise the handler
rt := regRouter.NewRouter(
router.WithHandler("http"),
router.WithRegistry(r),
router.WithRegister(r),
router.WithResolver(vpath.NewResolver(
resolver.WithServicePrefix(ns),
)),

View File

@@ -14,7 +14,7 @@ import (
"github.com/unistack-org/micro/v3/api"
"github.com/unistack-org/micro/v3/api/handler"
"github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/register"
)
const (
@@ -72,7 +72,7 @@ func (wh *webHandler) getService(r *http.Request) (string, error) {
}
// get the nodes
nodes := make([]*registry.Node, 0, len(service.Services))
nodes := make([]*register.Node, 0, len(service.Services))
for _, srv := range service.Services {
nodes = append(nodes, srv.Nodes...)
}

View File

@@ -3,7 +3,7 @@ package resolver
import (
"context"
"github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/register"
)
// Options struct
@@ -58,7 +58,7 @@ func Domain(n string) ResolveOption {
// NewResolveOptions returns new initialised resolve options
func NewResolveOptions(opts ...ResolveOption) ResolveOptions {
options := ResolveOptions{Domain: registry.DefaultDomain}
options := ResolveOptions{Domain: register.DefaultDomain}
for _, o := range opts {
o(&options)
}

View File

@@ -6,12 +6,12 @@ import (
"github.com/unistack-org/micro/v3/api/resolver"
"github.com/unistack-org/micro/v3/api/resolver/vpath"
"github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/register"
)
type Options struct {
Handler string
Registry registry.Registry
Register register.Register
Resolver resolver.Resolver
Logger logger.Logger
Context context.Context
@@ -52,10 +52,10 @@ func WithHandler(h string) Option {
}
}
// WithRegistry sets the registry
func WithRegistry(r registry.Registry) Option {
// WithRegister sets the register
func WithRegister(r register.Register) Option {
return func(o *Options) {
o.Registry = r
o.Register = r
}
}