func (r *Registry) Register(ctx context.Context, req *pb.Service, rsp *pb.EmptyResponse) error {
	var opts []registry.RegisterOption
	var domain string
	if req.Options != nil && req.Options.Ttl > 0 {
		ttl := time.Duration(req.Options.Ttl) * time.Second
		opts = append(opts, registry.RegisterTTL(ttl))
	}
	if req.Options != nil && len(req.Options.Domain) > 0 {
		domain = req.Options.Domain
	} else {
		domain = registry.DefaultDomain
	}
	opts = append(opts, registry.RegisterDomain(domain))
	if err := namespace.AuthorizeAdmin(ctx, domain, "registry.Registry.Register"); err != nil {
		return err
	}
	if err := registry.DefaultRegistry.Register(util.ToService(req), opts...); err != nil {
		return errors.InternalServerError("registry.Registry.Register", err.Error())
	}
	go r.publishEvent("create", req)
	return nil
}
Register a service
package handler
import (
	"context"
	"time"
	pb "github.com/micro/micro/v3/proto/registry"
	"github.com/micro/micro/v3/service"
	"github.com/micro/micro/v3/service/errors"
	log "github.com/micro/micro/v3/service/logger"
	"github.com/micro/micro/v3/service/registry"
	"github.com/micro/micro/v3/service/registry/util"
	"github.com/micro/micro/v3/util/auth/namespace"
)
type Registry struct {
	ID string
	Event *service.Event
}
func ActionToEventType(action string) registry.EventType {
	switch action {
	case "create":
		return registry.Create
	case "delete":
		return registry.Delete
	default:
		return registry.Update
	}
}
func (r *Registry) publishEvent(action string, service *pb.Service) error {
	event := &pb.Event{
		Id:        r.ID,
		Type:      pb.EventType(ActionToEventType(action)),
		Timestamp: time.Now().UnixNano(),
		Service:   service,
	}
	log.Debugf("publishing event %s for action %s", event.Id, action)
	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
	defer cancel()
	return r.Event.Publish(ctx, event)
}
func (r *Registry) GetService(ctx context.Context, req *pb.GetRequest, rsp *pb.GetResponse) error {
	var options registry.GetOptions
	if req.Options != nil && len(req.Options.Domain) > 0 {
		options.Domain = req.Options.Domain
	} else {
		options.Domain = registry.DefaultDomain
	}
	publicNS := namespace.Public(registry.DefaultDomain)
	if err := namespace.Authorize(ctx, options.Domain, "registry.Registry.GetService", publicNS); err != nil {
		return err
	}
	services, err := registry.DefaultRegistry.GetService(req.Service, registry.GetDomain(options.Domain))
	if err == registry.ErrNotFound || len(services) == 0 {
		return errors.NotFound("registry.Registry.GetService", registry.ErrNotFound.Error())
	} else if err != nil {
		return errors.InternalServerError("registry.Registry.GetService", err.Error())
	}
	rsp.Services = make([]*pb.Service, len(services))
	for i, srv := range services {
		rsp.Services[i] = util.ToProto(srv)
	}
	return nil
}