func generateResource(parent, name string, resource *raml.Resource, t *template.Template, f *os.File) string {
	path := parent + name
	for _, method := range resource.Methods() {
		err := t.Execute(f, HandlerInfo{ramlapi.Variableize(method.DisplayName), method.Name, path, method.Description})
		if err != nil {
			log.Println("executing template:", err)
		}
	}
	for nestname, nested := range resource.Nested {
		return generateResource(path, nestname, nested, t, f)
	}
	return path
}
generateResource creates a handler struct from an API resource
and executes the associated template.
package main
import (
	"flag"
	"log"
	"os"
	"os/exec"
	"text/template"
	"github.com/EconomistDigitalSolutions/ramlapi"
	"github.com/buddhamagnet/raml"
)
var (
	ramlFile string
	genFile  string
)
type RouteMapEntry struct {
	Name, Struct string
}
type HandlerInfo struct {
	Name, Verb, Path, Doc string
}
func init() {
	flag.StringVar(&ramlFile, "ramlfile", "api.raml", "RAML file to parse")
	flag.StringVar(&genFile, "genfile", "handlers_gen.go", "Filename to use for output")
}
func main() {
	flag.Parse()
	api, err := ramlapi.Process(ramlFile)
	if err != nil {
		log.Fatal(err)
	}
	log.Println("Processing API spec for", ramlFile)
	generate(api, genFile)
	log.Println("Created handlers in ", genFile)
}
func generate(api *raml.APIDefinition, genFile string) {
	f, err := os.Create(genFile)
	if err != nil {
		log.Fatal(err)
	}
	defer f.Close()
	f.WriteString(handlerHead)
	f.WriteString(mapStart)
	e := template.Must(template.New("mapEntry").Parse(mapEntry))
	for name, resource := range api.Resources {
		generateMap("", name, &resource, e, f)
	}
	f.WriteString(mapEnd)
	t := template.Must(template.New("handlerText").Parse(handlerText))
	for name, resource := range api.Resources {
		generateResource("", name, &resource, t, f)
	}
	format(f)
}
func format(f *os.File) {
	cmd := exec.Command("go", "fmt")
	cmd.Stdin = f
	_ = cmd.Run()
}