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: urls.go
    path of file: ./repos/juju/environs/tools
    
    the code of the file until where you have to start completion: // Copyright 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.

package tools

import (
	"sync"

	"github.com/juju/errors"

	"github.com/juju/juju/environs"
	conf "github.com/juju/juju/environs/config"
	"github.com/juju/juju/environs/simplestreams"
	"github.com/juju/juju/environs/storage"
	envutils "github.com/juju/juju/environs/utils"
	"github.com/juju/juju/juju/keys"
)

type toolsDatasourceFuncId struct {
	id string
	f  ToolsDataSourceFunc
}

var (
	toolsDatasourceFuncsMu sync.RWMutex
	toolsDatasourceFuncs   []toolsDatasourceFuncId
)

// ToolsDataSourceFunc is a function type that takes an environment and
// returns a simplestreams datasource.
//
// ToolsDataSourceFunc will be used in GetMetadataSources.
// Any error satisfying errors.IsNotSupported will be ignored;
// any other error will be cause GetMetadataSources to fail.
type ToolsDataSourceFunc func(environs.Environ) (simplestreams.DataSource, error)

// RegisterToolsDataSourceFunc registers an ToolsDataSourceFunc
// with the specified id, overwriting any function previously registered
// with the same id.
func RegisterToolsDataSourceFunc(id string, f ToolsDataSourceFunc) {
	toolsDatasourceFuncsMu.Lock()
	defer toolsDatasourceFuncsMu.Unlock()
	for i := range toolsDatasourceFuncs {
		if toolsDatasourceFuncs[i].id == id {
			toolsDatasourceFun
    
func GetMetadataSources(env environs.BootstrapEnviron, dataSourceFactory simplestreams.DataSourceFactory) ([]simplestreams.DataSource, error) {
	config := env.Config()

	// Add configured and environment-specific datasources.
	var sources []simplestreams.DataSource
	if userURL, ok := config.AgentMetadataURL(); ok {
		dataSourceConfig := simplestreams.Config{
			Description:          conf.AgentMetadataURLKey,
			BaseURL:              userURL,
			PublicSigningKey:     keys.JujuPublicKey,
			HostnameVerification: config.SSLHostnameVerification(),
			Priority:             simplestreams.SPECIFIC_CLOUD_DATA,
		}
		if err := dataSourceConfig.Validate(); err != nil {
			return nil, errors.Annotate(err, "simplestreams config validation failed")
		}
		dataSource := dataSourceFactory.NewDataSource(dataSourceConfig)
		sources = append(sources, dataSource)
	}

	envDataSources, err := environmentDataSources(env)
	if err != nil {
		return nil, err
	}
	sources = append(sources, envDataSources...)

	// Add the default, public datasource.
	defaultURL, err := ToolsURL(DefaultBaseURL)
	if err != nil {
		return nil, err
	}
	if defaultURL != "" {
		dataSourceConfig := simplestreams.Config{
			Description:          "default simplestreams",
			BaseURL:              defaultURL,
			PublicSigningKey:     keys.JujuPublicKey,
			HostnameVerification: true,
			Priority:             simplestreams.DEFAULT_CLOUD_DATA,
			RequireSigned:        DefaultBaseURL == streamsAgentURL,
		}
		if err := dataSourceConfig.Validate(); err != nil {
			return nil, errors.Annotate(err, "simplestreams config validation failed")
		}
		dataSource := dataSourceFactory.NewDataSource(dataSourceConfig)
		sources = append(sources, dataSource)
	}
	return sources, nil
}