Exemple #1
0
func goNameForNamedEntity(e compile.NamedEntity) (name string, fromAnnotation bool, err error) {
	fromAnnotation = true
	name, err = goNameAnnotation(e)
	if err == nil && name == "" {
		name = goCase(e.ThriftName())
		fromAnnotation = false
	}
	return name, fromAnnotation, err
}
Exemple #2
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
}