func collectTemplatePaths(templatePaths map[string]map[string]string, templateDir, excludeDir string) error { return filepath.Walk(templateDir, func(path string, info os.FileInfo, err error) error { if err != nil { return err } if info.IsDir() { if path == excludeDir { return filepath.SkipDir } return nil } baseName, err := filepath.Rel(templateDir, path) if err != nil { return err } name, ext := util.SplitExt(baseName) if _, exists := templatePaths[ext]; !exists { templatePaths[ext] = make(map[string]string) } if templatePath, exists := templatePaths[ext][name]; exists { return fmt.Errorf("duplicate name of template file:\n 1. %s\n 2. %s\n", templatePath, path) } templatePaths[ext][name] = path return nil }) }
func collectLayoutPaths(layoutPaths map[string]map[string]string, layoutDir string) error { return filepath.Walk(layoutDir, func(path string, info os.FileInfo, err error) error { if err != nil { return err } if info.IsDir() { return nil } baseName, err := filepath.Rel(layoutDir, path) if err != nil { return err } name, ext := util.SplitExt(baseName) if _, exists := layoutPaths[name]; !exists { layoutPaths[name] = make(map[string]string) } if layoutPath, exists := layoutPaths[name][ext]; exists { return fmt.Errorf("duplicate name of layout file:\n 1. %s\n 2. %s\n", layoutPath, path) } layoutPaths[name][ext] = path return nil }) }