Пример #1
0
func createControllerFile(projectName, controllerName string, stubs bool) {
	var filename string
	t := getTemplate("controller.tpl")
	if strutil.IsPascalCase(controllerName) {
		filename = strutil.Snakify(controllerName)
	} else {
		filename = strings.ToLower(controllerName)
		controllerName = strings.Title(controllerName)
	}
	path := filepath.Join(projectName, "controllers", filename+".go")
	importPath, _ := getImportPath(projectName)
	if f, err := os.Create(path); err != nil {
		fmt.Printf("Unable to create file controllers/%s.go: %s\n", filename, err)
	} else {
		defer f.Close()
		t.Execute(f, struct {
			Name, Project string
			Stubs         bool
		}{
			Name:    controllerName,
			Project: importPath,
			Stubs:   stubs,
		})
		fmt.Printf("Created %s\n", path)
	}
}
Пример #2
0
func createControllerFile(projectName, controllerName string) {
	var filename string
	t := getTemplate("controller.tpl")
	if strutil.IsPascalCase(controllerName) {
		filename = strutil.Snakify(controllerName)
	} else {
		filename = strings.ToLower(controllerName)
		controllerName = strings.Title(controllerName)
	}
	path := filepath.Join(projectName, "controllers", filename+".go")
	if f, err := os.Create(path); err != nil {
		fmt.Printf("Unable to create file controllers/%s.go: %s\n", filename, err)
	} else {
		defer f.Close()
		t.Execute(f, map[string]string{
			"name":    controllerName,
			"project": projectName,
		})
		fmt.Printf("Created %s\n", path)
	}
}