naming

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package naming implements protobuf-to-Go naming conventions aligned with protoc-gen-go. The core GoCamelCase function is ported from google.golang.org/protobuf/internal/strs (BSD-3-Clause license).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoCamelCase

func GoCamelCase(s string) string

GoCamelCase camel-cases a protobuf name for use as a Go identifier.

If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case.

Ported from google.golang.org/protobuf/internal/strs.GoCamelCase.

func GoEnumValueName

func GoEnumValueName(parentGoName, protoValueName string) string

GoEnumValueName returns the Go constant name for a protobuf enum value. The format is ParentGoName_PROTO_VALUE_NAME (no CamelCase on the value name itself), matching protoc-gen-go behavior.

parentGoName is the Go name of the containing type: the enum's Go name for top-level enums, or the message's Go name for enums nested in a message.

func GoFieldName

func GoFieldName(protoFieldName string) string

GoFieldName returns the Go struct field name for a protobuf field name. It applies GoCamelCase to convert snake_case to CamelCase.

func GoScalarType

func GoScalarType(kind model.ScalarKind) string

GoScalarType returns the Go type string for a protobuf scalar kind.

func GoTypeName

func GoTypeName(fullName, packageName string) string

GoTypeName returns the Go type name for a protobuf descriptor given its full name and the file's package name. Nested types use underscore separation (e.g., "Outer_Inner"), matching protoc-gen-go behavior.

The algorithm: strip the package prefix from the full name, then apply GoCamelCase to the remainder. Since GoCamelCase converts '.' followed by an uppercase letter to '_', nested types naturally get the Outer_Inner format.

func ResolveFieldNames

func ResolveFieldNames(rawNames []string) []string

ResolveFieldNames takes a slice of raw Go field names (already CamelCased) and returns a new slice with conflicts resolved. Each name is made unique against reserved names and previously assigned names, including their Get* accessors.

The order of the input slice matters: earlier fields claim names first, matching protoc-gen-go behavior.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL