Beispiel #1
0
func (cc CodeConfig) fileName(fileType string) string {
	switch fileType {
	case fileTypeMain:
		return "main.go"
	case fileTypeGitIgnore:
		return ".gitignore"
	case fileTypeConfig:
		return "config.go"
	case fileTypeConfigJson:
		return "config.json"
	case fileTypeGodepsJson:
		return "Godeps.json"
	case fileTypeGoDir:
		return ".godir"
	case fileTypeWebServer:
		return "server.go"
	case fileTypeDBType:
		return "base_model.go"
	case fileTypeSuiteTest:
		return "web_server_suite_test.go"
	case fileTypeController, fileTypeModel, fileTypeResource, fileTypeRoute:
		return gas.String(cc.EntityName).Underscore() + ".go"
	case fileTypeRequestTest:
		return gas.String(cc.EntityName).Underscore() + "_test.go"
	default:
		log.Panicln("Invalid File Type:", fileType)
	}

	return ""
}
Beispiel #2
0
func (cc CodeConfig) DasherizedEntityName(shouldPluralize bool) string {
	s := gas.String(cc.EntityName).Dasherize()
	if shouldPluralize {
		s = gas.String(s).Pluralize()
	}

	return s
}
Beispiel #3
0
func BuildJsonTag(name string, objectType string) string {
	var tag string
	name = gas.String(name).Dasherize()
	switch objectType {
	case "model":
		tag = `json:"` + name + `,omitempty"`
	case "resource":
		tag = `json:"` + name + `,omitempty" jsonapi:"name=` + name + `"`
	default:
		log.Panicln("invalid objectType for BuildJsonTag:", objectType)
	}

	return tag
}
Beispiel #4
0
func (cc CodeConfig) ParseModel() Model {
	var m Model

	if err := json.Unmarshal([]byte(cc.EntityDefinition), &m); err != nil {
		log.Fatalln("Could not parse model schemata:", err)
	}

	if cc.Debug {
		log.Println("--- Model Schemata ---")
		for i := range m.Schemata {
			schema := &m.Schemata[i]
			schema.DasherizedName = gas.String(schema.Name).Dasherize()
			schema.SortOrder = i
			log.Println(schema.Name+":"+schema.Type+":", schema.SortOrder)
		}
	}

	return m
}
Beispiel #5
0
func (cc CodeConfig) directoryName(fileType string) string {
	pluralizedFileType := gas.String(fileType).Pluralize()

	switch fileType {
	case fileTypeMain, fileTypeGitIgnore, fileTypeConfigJson, fileTypeGoDir:
		return "./" + cc.GoPath + "/"
	case fileTypeConfig:
		return "./" + cc.GoPath + "/config/"
	case fileTypeGodepsJson:
		return "./" + cc.GoPath + "/Godeps/"
	case fileTypeWebServer, fileTypeSuiteTest:
		return "./" + cc.GoPath + "/web_server/"
	case fileTypeDBType:
		return "./" + cc.GoPath + "/app/models/"
	case fileTypeController, fileTypeModel, fileTypeResource, fileTypeRoute:
		return "./app/" + pluralizedFileType + "/"
	case fileTypeRequestTest:
		return "./web_server/"
	default:
		log.Panicln("Invalid File Type:", fileType)
	}

	return ""
}
Beispiel #6
0
func (cc CodeConfig) PluralizedEntityName() string {
	return gas.String(cc.EntityName).Pluralize()
}