Exemplo n.º 1
0
// goNameAnnotation returns ("", nil) if there is no "go.name" annotation.
func goNameAnnotation(e compile.NamedEntity) (string, error) {
	name, ok := e.ThriftAnnotations()["go.name"]
	if !ok {
		return "", nil
	}

	c, _ := utf8.DecodeRuneInString(name)
	capitalized := unicode.IsLetter(c) && unicode.IsUpper(c)
	underscore := strings.Contains(name, "_")

	if !capitalized || underscore {
		var emsg []string
		if underscore {
			emsg = append(emsg, "contains underscores")
		}
		if !capitalized {
			emsg = append(emsg, "is not capitalized")
		}

		return "", fmt.Errorf("%q (from go.name annotation) is not a Go style public identifier (%s), suggestion: %q)", name, strings.Join(emsg, ", "), goCase(name))
	}

	return name, nil
}