clientarggen

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package clientarggen collects information for templating the code in a truss-generated client which marshals command line flags into message fields for each service. Functions and fields in clientargen are called by templates in protoc-gen-truss-gokit/template/

Index

Constants

This section is empty.

Variables

View Source
var ProtoToGoTypeMap = map[string]string{
	"TYPE_DOUBLE":   "float64",
	"TYPE_FLOAT":    "float32",
	"TYPE_INT64":    "int64",
	"TYPE_UINT64":   "uint64",
	"TYPE_INT32":    "int32",
	"TYPE_UINT32":   "uint32",
	"TYPE_FIXED64":  "uint64",
	"TYPE_FIXED32":  "uint32",
	"TYPE_BOOL":     "bool",
	"TYPE_STRING":   "string",
	"TYPE_SFIXED32": "int32",
	"TYPE_SFIXED64": "int64",
	"TYPE_SINT32":   "int32",
	"TYPE_SINT64":   "int64",
}

Functions

This section is empty.

Types

type ClientArg

type ClientArg struct {
	// Name contains the name of the arg as it appeared in the original
	// protobuf definition.
	Name string

	// FlagName is the name of the command line flag to be passed to set this
	// argument.
	FlagName string
	// FlagArg is the name of the Go variable that will hold the result of
	// parsing the command line flag.
	FlagArg string
	// FlagType is the the type provided to the flag library and determines the
	// Go type of the variable named FlagArg.
	FlagType string
	// FlagConvertFunc is the code for invoking the flag library to parse the
	// command line parameter named FlagName and store it in the Go variable
	// FlagArg.
	FlagConvertFunc string

	// GoArg is the Go variable that is of the same type as the corresponding
	// field of the message struct.
	GoArg string
	// GoType is the type of this arg's field on the message struct.
	GoType string
	// GoConvertInvoc is the code for initializing GoArg with either a typecast
	// from FlagArg or the invocation of a json unmarshal function.
	GoConvertInvoc string

	// IsBaseType is true if this arg corresponds to a protobuf field which is
	// any of the basic types, or a basic type but repeated. If this the field
	// was a nested message or a map, IsBaseType is false.
	IsBaseType bool
	// Repeated is true if this arg corresponds to a protobuf field which is
	// given an identifier of "repeated", meaning it will represented in Go as
	// a slice of it's type.
	Repeated bool
	// Enum is true if this arg corresponds to a protobuf field which is an
	// enum type.
	Enum bool
}

A collection of the necessary information for generating basic business logic in the client. This business logic will allow the generated client to:

  1. Have command line flags of the correct go types
  2. Place correctly named and typed arguments in each request method
  3. Create a request struct with the the function arguments as fields

Since we can only automatically generate handlers for some basic types, if a ClientArg is for a field that's not a base type (such as if it's an embedded message) then the developer is going to have to write a handler for that themselves.

type ClientServiceArgs

type ClientServiceArgs struct {
	MethArgs map[string]*MethodArgs
}

ClientServiceArgs is a map from the name of a method to a slice of all the ClientArgs for that method.

func New

func New(svc *svcdef.Service) *ClientServiceArgs

New creates a ClientServiceArgs struct containing all the arguments for all the methods of a given RPC.

func (*ClientServiceArgs) AllFlags

func (c *ClientServiceArgs) AllFlags() string

AllFlags returns a string that is all the flag declarations for all arguments of all methods, separated by newlines. This is used in the template to declare all the flag arguments for a client at once, and without doing all this iteration in a template where it would be much less understandable.

type MethodArgs

type MethodArgs struct {
	Args []*ClientArg
}

MethodArgs is a struct containing a slice of all the ClientArgs for this Method.

func (*MethodArgs) CallArgs

func (m *MethodArgs) CallArgs() string

CallArgs returns a string for the variables to pass to a function implementing this method. Example:

request, _ := clientHandler.Sum(ASum,  BSum)
                                └──────────┘

func (*MethodArgs) FunctionArgs

func (m *MethodArgs) FunctionArgs() string

FunctionArgs returns a string for the arguments of the function signature for a given method. E.g. If there where a method "Sum" with arguments "A" and "B", this would generate the arguments portion of a function declaration like this:

func Sum(ASum int64, BSum int64) (pb.SumRequest, error) {
         └────────────────────┘

func (*MethodArgs) MarshalFlags

func (m *MethodArgs) MarshalFlags() string

MarshalFlags returns the code for intantiating the GoArgs for this method while calling the code to marshal flag args into the correct go types. Example:

ASum := int32(flagASum)
└─────────────────────┘

Jump to

Keyboard shortcuts

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