code: func WriteToTextfile(filename string, g Gatherer) error {
  	tmp, err := ioutil.TempFile(filepath.Dir(filename), filepath.Base(filename))
  	if err != nil {
  		return err
  	}
  	defer os.Remove(tmp.Name())
  
  	mfs, err := g.Gather()
  	if err != nil {
  		return err
  	}
  	for _, mf := range mfs {
  		if _, err := expfmt.MetricFamilyToText(tmp, mf); err != nil {
  			return err
  		}
  	}
  	if err := tmp.Close(); err != nil {
  		return err
  	}
  
  	if err := os.Chmod(tmp.Name(), 0644); err != nil {
  		return err
  	}
  	return os.Rename(tmp.Name(), filename)
  }
docs: // WriteToTextfile calls Gather on the provided Gatherer, encodes the result in the
  // Prometheus text format, and writes it to a temporary file. Upon success, the
  // temporary file is renamed to the provided filename.
  //
  // This is intended for use with the textfile collector of the node exporter.
  // Note that the node exporter expects the filename to be suffixed with ".prom".