style(contrib/registry/*) annotation perfect (#2185)

Co-authored-by: xiongpan828@qq.com <panxiong@aithu.com>
pull/2085/head
潘雄 2 years ago committed by GitHub
parent d0a0edf67b
commit 96c8de9bc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      contrib/registry/eureka/client.go
  2. 4
      contrib/registry/eureka/register.go
  3. 8
      contrib/registry/kubernetes/registry.go

@ -37,7 +37,7 @@ type Endpoint struct {
MetaData map[string]string MetaData map[string]string
} }
// Response for /eureka/apps // ApplicationsRootResponse for /eureka/apps
type ApplicationsRootResponse struct { type ApplicationsRootResponse struct {
ApplicationsResponse `json:"applications"` ApplicationsResponse `json:"applications"`
} }

@ -59,7 +59,7 @@ func New(eurekaUrls []string, opts ...Option) (*Registry, error) {
return r, nil return r, nil
} }
// 这里的Context是每个注册器独享的 // Register 这里的Context是每个注册器独享的
func (r *Registry) Register(ctx context.Context, service *registry.ServiceInstance) error { func (r *Registry) Register(ctx context.Context, service *registry.ServiceInstance) error {
return r.api.Register(ctx, service.Name, r.Endpoints(service)...) return r.api.Register(ctx, service.Name, r.Endpoints(service)...)
} }
@ -86,7 +86,7 @@ func (r *Registry) GetService(ctx context.Context, serviceName string) ([]*regis
return items, nil return items, nil
} }
// watch 是独立的ctx // Watch 是独立的ctx
func (r *Registry) Watch(ctx context.Context, serviceName string) (registry.Watcher, error) { func (r *Registry) Watch(ctx context.Context, serviceName string) (registry.Watcher, error) {
return newWatch(ctx, r.api, serviceName) return newWatch(ctx, r.api, serviceName)
} }

@ -1,4 +1,4 @@
// The package registry simply implements the Kubernetes-based Registry // Package kuberegistry registry simply implements the Kubernetes-based Registry
package kuberegistry package kuberegistry
import ( import (
@ -78,7 +78,7 @@ const (
AnnotationsKeyProtocolMap = "kratos-service-protocols" AnnotationsKeyProtocolMap = "kratos-service-protocols"
) )
// The registry simply implements service discovery based on Kubernetes // The Registry simply implements service discovery based on Kubernetes
// It has not been verified in the production environment and is currently for reference only // It has not been verified in the production environment and is currently for reference only
type Registry struct { type Registry struct {
clientSet *kubernetes.Clientset clientSet *kubernetes.Clientset
@ -156,7 +156,7 @@ func (s *Registry) Deregister(ctx context.Context, service *registry.ServiceInst
}) })
} }
// Service return the service instances in memory according to the service name. // GetService return the service instances in memory according to the service name.
func (s *Registry) GetService(ctx context.Context, name string) ([]*registry.ServiceInstance, error) { func (s *Registry) GetService(ctx context.Context, name string) ([]*registry.ServiceInstance, error) {
pods, err := s.podLister.List(labels.SelectorFromSet(map[string]string{ pods, err := s.podLister.List(labels.SelectorFromSet(map[string]string{
LabelsKeyServiceName: name, LabelsKeyServiceName: name,
@ -258,7 +258,7 @@ func GetNamespace() string {
return currentNamespace return currentNamespace
} }
// GetNamespace is used to get the name of the Pod where the current container is located // GetPodName is used to get the name of the Pod where the current container is located
func GetPodName() string { func GetPodName() string {
return os.Getenv("HOSTNAME") return os.Getenv("HOSTNAME")
} }

Loading…
Cancel
Save