Imports
source ↗Imports
Protocol Buffer Messages and Stubs
Proto library imports are treated differently than standard Go imports due to their cross-language nature. The convention for renamed proto imports are based on the rule that generated the package:
- The
pbsuffix is generally used forgo_proto_libraryrules. - The
grpcsuffix is generally used forgo_grpc_libraryrules.
Often a single word describing the package is used:
// Good:
import (
foopb "path/to/package/foo_service_go_proto"
foogrpc "path/to/package/foo_service_go_grpc"
)
Follow the style guidance for package names. Prefer whole words. Short names are good, but avoid ambiguity. When in doubt, use the proto package name up to _go with a pb suffix:
// Good:
import (
pushqueueservicepb "path/to/package/push_queue_service_go_proto"
)
Note: Previous guidance encouraged very short names such as “xpb” or even just “pb”. New code should prefer more descriptive names. Existing code which uses short names should not be used as an example, but does not need to be changed.
Import ordering
See the Go Style Decisions: Import grouping.