Ejemplo n.º 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, "")
}
Ejemplo n.º 2
0
func processField(f *Field) {

	f.Name = alpha(exportName(preslash(f.Name)))

	//trim the field name by the hittype name (prevents ga.Event.EventAction)
	for _, h := range f.HitTypes {
		f.Name = goName(exportName(h), f.Name)
	}

	f.PrivateName = xstrings.FirstRuneToLower(f.Name)

	//these are manually defaulted
	if f.Name == "ProtocolVersion" || f.Name == "ClientID" {
		f.Required = false
	}

	//special case: DOCS ARE WRONG
	//these are not optional
	if strings.Contains(f.Docs, "Must not be empty.") {
		f.Docs = strings.Replace(f.Docs, "Must not be empty.", "", 1)
		f.Required = true
	}

	//special case:

	//unexport the hit type field
	if f.Name == "HitType" {
		f.Name = xstrings.FirstRuneToLower(f.Name)
	}

	f.Docs = comment(trim(f.Docs))
	f.Type = goType(f.Type)
	f.ParamStr = `"` + f.Param + `"`

	//check param for <extraVars>
	for _, i := range indexMatcher.FindAllString(f.Param, -1) {
		//extract each var
		newi := indexVar(i)
		f.Indices = append(f.Indices, newi)
		//convert param var into a string concat
		f.ParamStr = strings.Replace(f.ParamStr, i, `" + h.`+newi+` + "`, 1)
	}
}