func watchAndProcess(inFiles []string, outFile string, renderer Renderer) error {
	watcher, err := fsnotify.NewWatcher()
	if err != nil {
		return err
	}
	for _, inFile := range inFiles {
		watcher.Watch(inFile)
	}
	for {
		select {
		case event := <-watcher.Event:
			if event.IsModify() {
				if err := processFile(event.Name, outFile, renderer); err == nil {
					log.Println("Generating", event.Name, "->", outFile)
				} else {
					log.Println(event.Name, "-", err.Error())
				}
			}
		}
	}
}
Setup a watch process which will regenerate the files
package main
import (
	"flag"
	"fmt"
	"io"
	"io/ioutil"
	"log"
	"os"
	"path/filepath"
	"strings"
	"github.com/howeyc/fsnotify"
	"github.com/lmika/goseq/seqdiagram"
)
var flagOut = flag.String("o", "", "Output file")
var flagStyle = flag.String("s", "default", "The style to use")
var flagEmbedded = flag.Bool("e", false, "Generate an embedded SVG file")
var flagWatch = flag.Bool("w", false, "Watch for changes")
func die(msg string) {
	fmt.Fprintf(os.Stderr, "goseq: %s\n", msg)
	os.Exit(1)
}
func buildImageOptions() *seqdiagram.ImageOptions {
	style := seqdiagram.DefaultStyle
	if altStyle, hasStyle := seqdiagram.StyleNames[*flagStyle]; hasStyle {
		style = altStyle
	}
	return &seqdiagram.ImageOptions{
		Style:    style,
		Embedded: *flagEmbedded,
	}
}
func processMdFile(inFilename string, outFilename string, renderer Renderer) error {
	srcFile, err := openSourceFile(inFilename)
	if err != nil {
		return err
	}
	defer srcFile.Close()
	targetFile := ioutil.Discard
	mf := &MarkdownFilter{srcFile, targetFile, func(codeblock string, output io.Writer) error {
		fmt.Fprint(output, codeblock)
		err := processSeqDiagram(strings.NewReader(codeblock), inFilename, "/dev/null", nil)
		if err != nil {
			fmt.Fprintf(os.Stderr, "goseq: %s:embedded block - %s\n", inFilename, err.Error())
		}
		return nil
	}}
	return mf.Scan()
}
func processSeqFile(inFilename string, outFilename string, renderer Renderer) error {
	srcFile, err := openSourceFile(inFilename)
	if err != nil {
		return err
	}
	defer srcFile.Close()
	return processSeqDiagram(srcFile, inFilename, outFilename, renderer)
}
func processSeqDiagram(infile io.Reader, inFilename string, outFilename string, renderer Renderer) error {
	diagram, err := seqdiagram.ParseDiagram(infile, inFilename)
	if err != nil {
		return err
	}
	imageOptions := buildImageOptions()
	for _, pr := range diagram.ProcessingInstructions {
		if pr.Prefix == "goseq" {
			outFilename = pr.Value
		}
	}
	if renderer == nil {
		renderer, err = chooseRendererBaseOnOutfile(outFilename)
		if err != nil {
			return err
		}
	}
	err = renderer(diagram, imageOptions, outFilename)
	if err != nil {
		return err
	}
	return nil
}
func processFile(inFilename string, outFilename string, renderer Renderer) error {
	ext := filepath.Ext(inFilename)
	if ext == ".md" {
		return processMdFile(inFilename, outFilename, renderer)
	} else {
		return processSeqFile(inFilename, outFilename, renderer)
	}
}