Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
registry refact 3.27
  • Loading branch information
vito.he
vito.he committed Mar 27, 2019
commit 33db59177f616a1acfc265614d88f9907e643d02
4 changes: 2 additions & 2 deletions examples/go-client/app/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package main

import (
"fmt"
"github.com/dubbo/dubbo-go/plugins"
"github.com/dubbo/dubbo-go/registry/zookeeper"
"net/http"
_ "net/http/pprof"
"os"
Expand All @@ -21,6 +19,8 @@ import (
)

import (
"github.com/dubbo/dubbo-go/plugins"
"github.com/dubbo/dubbo-go/registry/zookeeper"
"github.com/dubbo/dubbo-go/public"
"github.com/dubbo/dubbo-go/registry"
)
Expand Down
3 changes: 2 additions & 1 deletion examples/go-server/app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/dubbo/dubbo-go/registry/zookeeper"
"github.com/dubbo/dubbo-go/server"
"io/ioutil"
"os"
"path"
Expand Down Expand Up @@ -42,7 +43,7 @@ type (
Registry string `default:"zookeeper" yaml:"registry" json:"registry,omitempty"`
ZkRegistryConfig zookeeper.ZkRegistryConfig `yaml:"zk_registry_config" json:"zk_registry_config,omitempty"`
Service_List []registry.ServiceConfig `yaml:"service_list" json:"service_list,omitempty"`
Server_List []registry.ServerConfig `yaml:"server_list" json:"server_list,omitempty"`
Server_List []server.ServerConfig `yaml:"server_list" json:"server_list,omitempty"`
}
)

Expand Down
5 changes: 3 additions & 2 deletions jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"bytes"
"context"
"github.com/dubbo/dubbo-go/server"
"io/ioutil"
"net"
"net/http"
Expand Down Expand Up @@ -55,7 +56,7 @@ type Option func(*Options)

type Options struct {
Registry registry.Registry
ConfList []registry.ServerConfig
ConfList []server.ServerConfig
ServiceConfList []registry.ServiceConfig
Timeout time.Duration
}
Expand All @@ -80,7 +81,7 @@ func Registry(r registry.Registry) Option {
}
}

func ConfList(confList []registry.ServerConfig) Option {
func ConfList(confList []server.ServerConfig) Option {
return func(o *Options) {
o.ConfList = confList
for i := 0; i < len(o.ConfList); i++ {
Expand Down
83 changes: 83 additions & 0 deletions registry/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package registry

import (
"time"
)

const (
CONSUMER = iota
CONFIGURATOR
ROUTER
PROVIDER
)

var (
DubboNodes = [...]string{"consumers", "configurators", "routers", "providers"}
DubboRole = [...]string{"consumer", "", "", "provider"}
)
type DubboType int

func (t DubboType) String() string {
return DubboNodes[t]
}

func (t DubboType) Role() string {
return DubboRole[t]
}
type ApplicationConfig struct {
Organization string `yaml:"organization" json:"organization,omitempty"`
Name string `yaml:"name" json:"name,omitempty"`
Module string `yaml:"module" json:"module,omitempty"`
Version string `yaml:"version" json:"version,omitempty"`
Owner string `yaml:"owner" json:"owner,omitempty"`
Environment string `yaml:"environment" json:"environment,omitempty"`
}




type OptionInf interface{
OptionName()string
}
type Options struct{
ApplicationConfig
Mode Mode
ServiceTTL time.Duration
DubboType DubboType
}



//func (c *ApplicationConfig) ToString() string {
// return fmt.Sprintf("ApplicationConfig is {name:%s, version:%s, owner:%s, module:%s, organization:%s}",
// c.Name, c.Version, c.Owner, c.Module, c.Organization)
//}

type Option func(*Options)

func(Option)OptionName() string {
return "Abstact option func"
}

func WithDubboType(tp DubboType)Option{
return func (o *Options){
o.DubboType = tp
}
}

func WithApplicationConf(conf ApplicationConfig) Option {
return func(o *Options) {
o.ApplicationConfig = conf
}
}

func WithServiceTTL(ttl time.Duration) Option {
return func(o *Options) {
o.ServiceTTL = ttl
}
}
func WithBalanceMode(mode Mode) Option {
return func(o *Options) {
o.Mode = mode
}
}
86 changes: 0 additions & 86 deletions registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,12 @@ package registry

import (
"fmt"
"time"
)

import (
"github.com/AlexStocks/goext/net"
)

//////////////////////////////////////////////
// Registry Interface
//////////////////////////////////////////////

const (
CONSUMER = iota
CONFIGURATOR
ROUTER
PROVIDER
)

var (
DubboNodes = [...]string{"consumers", "configurators", "routers", "providers"}
DubboRole = [...]string{"consumer", "", "", "provider"}
)
type DubboType int

func (t DubboType) String() string {
return DubboNodes[t]
}

func (t DubboType) Role() string {
return DubboRole[t]
}


// for service discovery/registry
Expand All @@ -54,43 +29,6 @@ type Registry interface {
NewProviderServiceConfig(ServiceConfig)ServiceConfigIf
}

type OptionInf interface{
OptionName()string
}
type Options struct{
ApplicationConfig
Mode Mode
ServiceTTL time.Duration
DubboType DubboType
}
type Option func(*Options)

func(Option)OptionName() string {
return "Abstact option func"
}

func WithDubboType(tp DubboType)Option{
return func (o *Options){
o.DubboType = tp
}
}

func WithApplicationConf(conf ApplicationConfig) Option {
return func(o *Options) {
o.ApplicationConfig = conf
}
}

func WithServiceTTL(ttl time.Duration) Option {
return func(o *Options) {
o.ServiceTTL = ttl
}
}
func WithBalanceMode(mode Mode) Option {
return func(o *Options) {
o.Mode = mode
}
}

//////////////////////////////////////////////
// service config
Expand Down Expand Up @@ -139,27 +77,3 @@ func (c ServiceConfig) ServiceEqual(url *ServiceURL) bool {
return true
}

type ServerConfig struct {
Protocol string `required:"true",default:"dubbo" yaml:"protocol" json:"protocol,omitempty"` // codec string, jsonrpc etc
IP string `yaml:"ip" json:"ip,omitempty"`
Port int `required:"true" yaml:"port" json:"port,omitempty"`
}

func (c *ServerConfig) Address() string {
return gxnet.HostAddress(c.IP, c.Port)
}


type ApplicationConfig struct {
Organization string `yaml:"organization" json:"organization,omitempty"`
Name string `yaml:"name" json:"name,omitempty"`
Module string `yaml:"module" json:"module,omitempty"`
Version string `yaml:"version" json:"version,omitempty"`
Owner string `yaml:"owner" json:"owner,omitempty"`
Environment string `yaml:"environment" json:"environment,omitempty"`
}

func (c *ApplicationConfig) ToString() string {
return fmt.Sprintf("ApplicationConfig is {name:%s, version:%s, owner:%s, module:%s, organization:%s}",
c.Name, c.Version, c.Owner, c.Module, c.Organization)
}
1 change: 0 additions & 1 deletion registry/zookeeper/zookeeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ func (r *ZkRegistry) register(c interface{}) error {
return jerrors.Trace(err)
}

params = url.Values{}
params.Add("protocol", conf.Protocol)
params.Add("interface", conf.Service)
revision = r.ApplicationConfig.Version
Expand Down
15 changes: 15 additions & 0 deletions server/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package server

import "github.com/AlexStocks/goext/net"

type ServerConfig struct {
Protocol string `required:"true",default:"dubbo" yaml:"protocol" json:"protocol,omitempty"` // codec string, jsonrpc etc
IP string `yaml:"ip" json:"ip,omitempty"`
Port int `required:"true" yaml:"port" json:"port,omitempty"`
}

func (c *ServerConfig) Address() string {
return gxnet.HostAddress(c.IP, c.Port)
}