rename Registry to Endpointer (#964)

pull/965/head
Tony Chen 4 years ago committed by GitHub
parent 41ea1fbc76
commit 4cb3fd62e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app.go
  2. 4
      transport/grpc/server.go
  3. 4
      transport/http/server.go
  4. 10
      transport/transport.go

@ -113,7 +113,7 @@ func (a *App) Stop() error {
func buildInstance(o options) (*registry.ServiceInstance, error) {
if len(o.endpoints) == 0 {
for _, srv := range o.servers {
if r, ok := srv.(transport.Registry); ok {
if r, ok := srv.(transport.Endpointer); ok {
e, err := r.Endpoint()
if err != nil {
return nil, err

@ -20,7 +20,7 @@ import (
)
var _ transport.Server = (*Server)(nil)
var _ transport.Registry = (*Server)(nil)
var _ transport.Endpointer = (*Server)(nil)
// ServerOption is gRPC server option.
type ServerOption func(o *Server)
@ -117,7 +117,7 @@ func NewServer(opts ...ServerOption) *Server {
// examples:
// grpc://127.0.0.1:9000?isSecure=false
func (s *Server) Endpoint() (string, error) {
if strings.HasSuffix(s.address, ":0") {
if s.lis == nil && strings.HasSuffix(s.address, ":0") {
lis, err := net.Listen(s.network, s.address)
if err != nil {
return "", err

@ -17,7 +17,7 @@ import (
)
var _ transport.Server = (*Server)(nil)
var _ transport.Registry = (*Server)(nil)
var _ transport.Endpointer = (*Server)(nil)
// ServerOption is HTTP server option.
type ServerOption func(*Server)
@ -105,7 +105,7 @@ func (s *Server) ServeHTTP(res http.ResponseWriter, req *http.Request) {
// examples:
// http://127.0.0.1:8000?isSecure=false
func (s *Server) Endpoint() (string, error) {
if strings.HasSuffix(s.address, ":0") {
if s.lis == nil && strings.HasSuffix(s.address, ":0") {
lis, err := net.Listen(s.network, s.address)
if err != nil {
return "", err

@ -10,17 +10,17 @@ import (
_ "github.com/go-kratos/kratos/v2/encoding/yaml"
)
// Registry is registry endpoint.
type Registry interface {
Endpoint() (string, error)
}
// Server is transport server.
type Server interface {
Start() error
Stop() error
}
// Endpointer is registry endpoint.
type Endpointer interface {
Endpoint() (string, error)
}
// Transport is transport context value.
type Transport struct {
Kind Kind

Loading…
Cancel
Save