Пример #1
0
func snake(s string, private bool, acronyms map[string]string) string {
	var parts []string
	parts1 := strings.Split(s, "_")
	for _, p1 := range parts1 {
		parts2 := strings.Split(p1, "/")
		for _, p2 := range parts2 {
			parts3 := strings.Split(p2, "-")
			parts = append(parts, parts3...)
		}
	}

	for i, part := range parts {
		if !private || i > 0 {
			if formatted, ok := acronyms[part]; ok {
				parts[i] = formatted

				continue
			}
		}

		parts[i] = xstrings.FirstRuneToUpper(part)
	}

	if private {
		parts[0] = xstrings.FirstRuneToLower(parts[0])
	}
	return strings.Join(parts, "")
}
Пример #2
0
func exportName(s string) string {
	words := strings.Split(s, " ")
	for i, w := range words {
		words[i] = xstrings.FirstRuneToUpper(w)
	}
	return strings.Join(words, "")
}
Пример #3
0
func processHitType(h *HitType) {

	h.StructName = exportName(h.Name)

	//set of index vars
	is := map[string]bool{}
	for _, f := range h.Fields {
		//add all index vars to the set
		for _, i := range f.Indices {
			is[i] = true
		}
	}
	//extra psuedo-fields to be added
	for i, _ := range is {
		h.Indices = append(h.Indices, i)
	}
	sort.Strings(h.Indices)

	//ordered indicies
	for _, i := range h.Indices {
		h.Fields = append(h.Fields, &Field{
			Name:        xstrings.FirstRuneToUpper(i),
			PrivateName: i,
			Type:        "string",
			Docs:        "// " + xstrings.FirstRuneToUpper(i) + " is required by other properties",
		})
	}

	//place all non-client hittype ids in client for templating
	if h.Name == "client" {
		for _, h2 := range hitTypes {
			if h2.Name != "client" {
				h.HitTypeIDs = append(h.HitTypeIDs, h2.Name)
			}
		}
		sort.Strings(h.HitTypeIDs)
	}
}