You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: registry.go
    path of file: ./repos/kratos/contrib/polaris
    
    the code of the file until where you have to start completion: package polaris

import (
	"context"
	"fmt"
	"net"
	"net/url"
	"strconv"
	"time"

	"github.com/google/uuid"
	"github.com/polarismesh/polaris-go"
	"github.com/polarismesh/polaris-go/pkg/model"

	"github.com/go-kratos/kratos/v2/registry"
)

var (
	_ registry.Registrar = (*Registry)(nil)
	_ registry.Discovery = (*Registry)(nil)
)

type registryOptions struct {
	// required, testNamespace in polaris
	Namespace string

	// required, service access token
	ServiceToken string

	// service
    
func (r *Registry) Register(_ context.Context, instance *registry.ServiceInstance) error {
	id := uuid.NewString()
	for _, endpoint := range instance.Endpoints {
		u, err := url.Parse(endpoint)
		if err != nil {
			return err
		}

		host, port, err := net.SplitHostPort(u.Host)
		if err != nil {
			return err
		}

		portNum, err := strconv.Atoi(port)
		if err != nil {
			return err
		}

		// metadata
		if instance.Metadata == nil {
			instance.Metadata = make(map[string]string)
		}
		instance.Metadata["merge"] = id
		if _, ok := instance.Metadata["weight"]; !ok {
			instance.Metadata["weight"] = strconv.Itoa(r.opt.Weight)
		}

		weight, _ := strconv.Atoi(instance.Metadata["weight"])

		_, err = r.provider.RegisterInstance(
			&polaris.InstanceRegisterRequest{
				InstanceRegisterRequest: model.InstanceRegisterRequest{
					Service:      instance.Name,
					ServiceToken: r.opt.ServiceToken,
					Namespace:    r.opt.Namespace,
					Host:         host,
					Port:         portNum,
					Protocol:     &u.Scheme,
					Weight:       &weight,
					Priority:     &r.opt.Priority,
					Version:      &instance.Version,
					Metadata:     instance.Metadata,
					Healthy:      &r.opt.Healthy,
					Isolate:      &r.opt.Isolate,
					TTL:          &r.opt.TTL,
					Timeout:      &r.opt.Timeout,
					RetryCount:   &r.opt.RetryCount,
				},
			},
		)
		if err != nil {
			return err
		}
	}
	return nil
}