Package pgsgo contains Go-specific helpers for use with PG* based protoc-plugins




    This section is empty.


    This section is empty.


    func AddImportMapping

    func AddImportMapping(p pgs.Parameters, proto, pkg string)

      AddImportMapping adds a proto file to Go package import mapping to the parameters.

      func AddPlugin

      func AddPlugin(p pgs.Parameters, name ...string)

        AddPlugin adds name to the list of plugins in the parameters. If all plugins are enabled, this method is a noop.

        func EnableAllPlugins

        func EnableAllPlugins(p pgs.Parameters)

          EnableAllPlugins changes the parameters to enable all registered sub-plugins.

          func GoFmt

          func GoFmt() pgs.PostProcessor

            GoFmt returns a PostProcessor that runs gofmt on any files ending in ".go"

            func HasPlugin

            func HasPlugin(p pgs.Parameters, name string) bool

              HasPlugin returns true if the plugin name is enabled in the parameters. This method will always return true if all plugins are enabled.

              func ImportPath

              func ImportPath(p pgs.Parameters) string

                ImportPath returns the protoc-gen-go parameter. This value is used as the package if the input proto files do not declare a go_package option. If it contains slashes, everything up to the rightmost slash is ignored.


                func ImportPrefix

                func ImportPrefix(p pgs.Parameters) string

                  ImportPrefix returns the protoc-gen-go parameter. This prefix is added onto the beginning of all Go import paths. This is useful for things like generating protos in a subdirectory, or regenerating vendored protobufs in-place. By default, this method returns an empty string.


                  func MappedImport

                  func MappedImport(p pgs.Parameters, proto string) (string, bool)

                    MappedImport returns the protoc-gen-go import overrides for the specified proto file. Each entry in the map keys off a proto file (as loaded by protoc) with values of the Go package to use. These values will be prefixed with the value of ImportPrefix when generating the Go code.

                    func PGGUpperCamelCase

                    func PGGUpperCamelCase(n pgs.Name) pgs.Name

                      PGGUpperCamelCase converts Name n to the protoc-gen-go defined upper camelcase. The rules are slightly different from pgs.UpperCamelCase in that leading underscores are converted to 'X', mid-string underscores followed by lowercase letters are removed and the letter is capitalized, all other punctuation is preserved. This method should be used when deriving names of protoc-gen-go generated code (ie, message/service struct names and field names).


                      func Plugins

                      func Plugins(p pgs.Parameters) (plugins []string, all bool)

                        Plugins returns the sub-plugins enabled for this protoc plugin. If the all value is true, all registered plugins are considered enabled (ie, protoc was called with an empty "plugins" parameter). Otherwise, plugins contains the list of plugins enabled by name.

                        func SetImportPath

                        func SetImportPath(p pgs.Parameters, path string)

                          SetImportPath sets the protoc-gen-go ImportPath parameter. This is useful for overriding the behavior of the ImportPath at runtime.

                          func SetImportPrefix

                          func SetImportPrefix(p pgs.Parameters, prefix string)

                            SetImportPrefix sets the protoc-gen-go ImportPrefix parameter. This is useful for overriding the behavior of the ImportPrefix at runtime.

                            func SetPaths

                            func SetPaths(p pgs.Parameters, pt PathType)

                              SetPaths sets the protoc-gen-go Paths parameter. This is useful for overriding the behavior of Paths at runtime.


                              type Context

                              type Context interface {
                              	// Params returns the Parameters associated with this context.
                              	Params() pgs.Parameters
                              	// Name returns the name of a Node as it would appear in the generation output
                              	// of protoc-gen-go. For each type, the following is returned:
                              	//     - Package: the Go package name
                              	//     - File: the Go package name
                              	//     - Message: the struct name
                              	//     - Field: the field name on the Message struct
                              	//     - OneOf: the field name on the Message struct
                              	//     - Enum: the type name
                              	//     - EnumValue: the constant name
                              	//     - Service: the server interface name
                              	//     - Method: the method name on the server and client interface
                              	Name(node pgs.Node) pgs.Name
                              	// ServerName returns the name of the server interface for the Service.
                              	ServerName(service pgs.Service) pgs.Name
                              	// ClientName returns the name of the client interface for the Service.
                              	ClientName(service pgs.Service) pgs.Name
                              	// ServerStream returns the name of the grpc.ServerStream wrapper for this
                              	// method. This name is only used if client or server streaming is
                              	// implemented for this method.
                              	ServerStream(method pgs.Method) pgs.Name
                              	// OneofOption returns the struct name that wraps a OneOf option's value. These
                              	// messages contain one field, matching the value returned by Name for this
                              	// Field.
                              	OneofOption(field pgs.Field) pgs.Name
                              	// TypeName returns the type name of a Field as it would appear in the
                              	// generated message struct from protoc-gen-go. Fields from imported
                              	// packages will be prefixed with the package name.
                              	Type(field pgs.Field) TypeName
                              	// PackageName returns the name of the Node's package as it would appear in
                              	// Go source generated by the official protoc-gen-go plugin.
                              	PackageName(node pgs.Node) pgs.Name
                              	// ImportPath returns the Go import path for an entity as it would be
                              	// included in an import block in a Go file. This value is only appropriate
                              	// for Entities imported into a target file/package.
                              	ImportPath(entity pgs.Entity) pgs.FilePath
                              	// OutputPath returns the output path relative to the plugin's output destination
                              	OutputPath(entity pgs.Entity) pgs.FilePath

                                Context resolves Go-specific language for Packages & Entities generated by protoc-gen-go. The rules that drive the naming behavior are complicated, and result from an interplay of the go_package file option, the proto package, and the proto filename itself. Therefore, it is recommended that all proto files that are targeting Go should include a fully qualified go_package option. These must be consistent for all proto files that are intended to be in the same Go package.

                                func InitContext

                                func InitContext(params pgs.Parameters) Context

                                  InitContext configures a Context that should be used for deriving Go names for all Packages and Entities.

                                  type PathType

                                  type PathType string

                                    PathType describes how the generated output file paths should be constructed.

                                    const (
                                    	// ImportPathRelative is the default and outputs the file based off the go
                                    	// import path defined in the go_package option.
                                    	ImportPathRelative PathType = ""
                                    	// SourceRelative indicates files should be output relative to the path of
                                    	// the source file.
                                    	SourceRelative PathType = "source_relative"

                                    func Paths

                                    func Paths(p pgs.Parameters) PathType

                                      Paths returns the protoc-gen-go parameter. This value is used to switch the mode used to determine the output paths of the generated code. By default, paths are derived from the import path specified by go_package. It can be overridden to be "source_relative", ignoring the import path using the source path exclusively.

                                      type TypeName

                                      type TypeName string

                                        A TypeName describes the name of a type (type on a field, or method signature)

                                        func (TypeName) Element

                                        func (n TypeName) Element() TypeName

                                          Element returns the TypeName of the element of n. For types other than slices and maps, this just returns n.


                                          func (TypeName) IsPointer

                                          func (n TypeName) IsPointer() bool

                                            IsPointer reports whether TypeName n is a pointer type, slice or a map.


                                            func (TypeName) Key

                                            func (n TypeName) Key() TypeName

                                              Key returns the TypeName of the key of n. For slices, the return TypeName is always "int", and for non slice/map types an empty TypeName is returned.


                                              func (TypeName) Pointer

                                              func (n TypeName) Pointer() TypeName

                                                Pointer converts TypeName n to it's pointer type. If n is already a pointer, slice, or map, it is returned unmodified.


                                                func (TypeName) String

                                                func (n TypeName) String() string

                                                  String satisfies the strings.Stringer interface.

                                                  func (TypeName) Value

                                                  func (n TypeName) Value() TypeName

                                                    Value converts TypeName n to it's value type. If n is already a value type, slice, or map it is returned unmodified.