示例#1
0
文件: main.go 项目: balrajb/goberry
// 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) {
	var resourcepath = parent + name
	type RouteMapEntry struct {
		Name, Struct string
	}

	for verb, n := range ramlapi.ResourceVerbs(resource) {
		if n == "" {
			log.Fatalf("no handler name specified for %s via %s\n", resourcepath, verb)
		}
		err := e.Execute(f, RouteMapEntry{n, n})
		if err != nil {
			log.Println("executing template:", err)
		}
	}

	// Get all children.
	for nestname, nested := range resource.Nested {
		generateMap(resourcepath, nestname, nested, e, f)
	}
}
示例#2
0
文件: main.go 项目: balrajb/goberry
// 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 {
	var resourcepath = parent + name
	type HandlerInfo struct {
		Name, Verb, Path, Doc string
	}

	for verb, n := range ramlapi.ResourceVerbs(resource) {
		if n == "" {
			log.Fatalf("no handler name specified for %s via %s\n", resourcepath, verb)
		}
		err := t.Execute(f, HandlerInfo{n, verb, resourcepath, resource.Description})
		if err != nil {
			log.Println("executing template:", err)
		}
	}

	// Get all children.
	for nestname, nested := range resource.Nested {
		return generateResource(resourcepath, nestname, nested, t, f)
	}
	return resourcepath
}