label_sync/main.go
func writeTemplate(templatePath string, outputPath string, data interface{}) error {
	// set up template
	funcMap := template.FuncMap{
		"anchor": func(input string) string {
			return strings.Replace(input, ":", " ", -1)
		},
	}
	t, err := template.New(filepath.Base(templatePath)).Funcs(funcMap).ParseFiles(templatePath)
	if err != nil {
		return err
	}

	// ensure output path exists
	if !pathExists(outputPath) {
		_, err = os.Create(outputPath)
		if err != nil {
			return err
		}
	}

	// open file at output path and truncate
	f, err := os.OpenFile(outputPath, os.O_RDWR, 0644)
	if err != nil {
		return err
	}
	defer f.Close()
	f.Truncate(0)

	// render template to output path
	err = t.Execute(f, data)
	if err != nil {
		return err
	}

	return nil
}
func writeTemplate(templatePath string, outputPath string, data interface{}) error {
	// set up template
	funcMap := template.FuncMap{
		"anchor": func(input string) string {
			return strings.Replace(input, ":", " ", -1)
		},
	}
	t, err := template.New(filepath.Base(templatePath)).Funcs(funcMap).ParseFiles(templatePath)
	if err != nil {
		return err
	}

	// ensure output path exists
	if !pathExists(outputPath) {
		_, err = os.Create(outputPath)
		if err != nil {
			return err
		}
	}

	// open file at output path and truncate
	f, err := os.OpenFile(outputPath, os.O_RDWR, 0644)
	if err != nil {
		return err
	}
	defer f.Close()
	f.Truncate(0)

	// render template to output path
	err = t.Execute(f, data)
	if err != nil {
		return err
	}

	return nil
}
func writeTemplate ( templatePath string , outputPath string , data interface { } ) error { // set up template funcMap := template . FuncMap { " " : func ( input string ) string { return strings . Replace ( input , " " , " " , - 1 ) } , } t , err := template . New ( filepath . Base ( templatePath ) ) . Funcs ( funcMap ) . ParseFiles ( templatePath ) if err != nil { return err } // ensure output path exists if ! pathExists ( outputPath ) { _ , err = os . Create ( outputPath ) if err != nil { return err } } // open file at output path and truncate f , err := os . OpenFile ( outputPath , os . O_RDWR , 0644 ) if err != nil { return err } defer f . Close ( ) f . Truncate ( 0 ) // render template to output path err = t . Execute ( f , data ) if err != nil { return err } return nil }
// Writes the golang text template at templatePath to outputPath using the given data
Writes the golang text template at templatePath to outputPath using the given data