code: func (daemon *Daemon) NewResolveOptionsFunc() resolver.ResolveOptionsFunc {
  	return func(ref string) docker.ResolverOptions {
  		var (
  			registryKey = "docker.io"
  			mirrors     = make([]string, len(daemon.configStore.Mirrors))
  			m           = map[string]resolver.RegistryConf{}
  		)
  		// must trim "https://" or "http://" prefix
  		for i, v := range daemon.configStore.Mirrors {
  			if uri, err := url.Parse(v); err == nil {
  				v = uri.Host
  			}
  			mirrors[i] = v
  		}
  		// set "registry-mirrors"
  		m[registryKey] = resolver.RegistryConf{Mirrors: mirrors}
  		// set "insecure-registries"
  		for _, v := range daemon.configStore.InsecureRegistries {
  			if uri, err := url.Parse(v); err == nil {
  				v = uri.Host
  			}
  			m[v] = resolver.RegistryConf{
  				PlainHTTP: true,
  			}
  		}
  		def := docker.ResolverOptions{
  			Client: tracing.DefaultClient,
  		}
  
  		parsed, err := reference.ParseNormalizedNamed(ref)
  		if err != nil {
  			return def
  		}
  		host := reference.Domain(parsed)
  
  		c, ok := m[host]
  		if !ok {
  			return def
  		}
  
  		if len(c.Mirrors) > 0 {
  			def.Host = func(string) (string, error) {
  				return c.Mirrors[rand.Intn(len(c.Mirrors))], nil
  			}
  		}
  
  		def.PlainHTTP = c.PlainHTTP
  
  		return def
  	}
  }
docs: // NewResolveOptionsFunc returns a call back function to resolve "registry-mirrors" and
  // "insecure-registries" for buildkit