// generateResource creates a handler struct from an API resource // and executes the associated template. 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) } } // Get all children. for nestname, nested := range resource.Nested { return generateResource(path, nestname, nested, t, f) } return path }
// generateMap builds a map of string labels to handler funcs - this is // used by the calling code to link the display name strings that come // from the RAML file to handler funcs in the client code. func generateMap(parent, name string, resource *raml.Resource, e *template.Template, f *os.File) { path := parent + name for _, method := range resource.Methods() { name := ramlapi.Variableize(method.DisplayName) err := e.Execute(f, RouteMapEntry{name, name}) if err != nil { log.Println("executing template:", err) } } // Get all children. for nestname, nested := range resource.Nested { generateMap(path, nestname, nested, e, f) } }