code: func genDiscoveryFile(c context.Context, target, descFile, protoPkg, goPkg string) error {
  	descBytes, err := ioutil.ReadFile(descFile)
  	if err != nil {
  		return err
  	}
  
  	var desc descriptor.FileDescriptorSet
  	if err := proto.Unmarshal(descBytes, &desc); err != nil {
  		return fmt.Errorf("cannot parse generated descriptor file: %s", err)
  	}
  
  	var serviceNames []string
  	for _, f := range desc.File {
  		for _, s := range f.Service {
  			serviceNames = append(serviceNames, fmt.Sprintf("%s.%s", protoPkg, s.GetName()))
  		}
  	}
  	if len(serviceNames) == 0 {
  		// no services, no discovery.
  		return nil
  	}
  
  	compressedDescBytes, err := compress(descBytes)
  	if err != nil {
  		return err
  	}
  
  	inDiscoveryPackage, err := isInPackage(target, discoveryPackagePath)
  	if err != nil {
  		return err
  	}
  
  	var buf bytes.Buffer
  	err = discoveryTmpl.Execute(&buf, map[string]interface{}{
  		"GoPkg":           goPkg,
  		"ImportDiscovery": !inDiscoveryPackage,
  		"ServiceNames":    serviceNames,
  		"CompressedBytes": asByteArray(compressedDescBytes),
  	})
  	if err != nil {
  		return err
  	}
  
  	src := buf.Bytes()
  	formatted, err := gofmt(src)
  	if err != nil {
  		os.Stdout.Write(src)
  		return err
  	}
  	return ioutil.WriteFile(target, formatted, 0666)
  }
docs: // genDiscoveryFile generates a Go discovery file that calls
  // discovery.RegisterDescriptorSetCompressed(serviceNames, compressedDescBytes)
  // in an init function.