Documentation ¶
Index ¶
- Constants
- Variables
- func CamelCase(src string) string
- func CamelToSnake(s string) string
- func ExecuteDefaultOrCustomTemplate(defaultTemplateName string, defaultTemplates *Template, ...) (ret []byte, rErr error)
- func FindClientsWithFixture(instance *ModuleInstance) (map[string]string, error)
- func FormatGoFile(filePath string) error
- func GenerateDependencyStruct(instance *ModuleInstance, packageHelper *PackageHelper, template *Template) ([]byte, error)
- func GenerateInitializer(instance *ModuleInstance, packageHelper *PackageHelper, template *Template) ([]byte, error)
- func GetClientQPSLevels(qpsLevels map[string]int, methods map[string]string, clientID string) map[string]string
- func GetListOfAllFilesInEndpointDir(filePath string, filesList []string) ([]string, error)
- func GoCustomType(p PackageNameResolver, spec compile.TypeSpec) (string, error)
- func GoReferenceType(p PackageNameResolver, spec compile.TypeSpec) (string, error)
- func GoType(p PackageNameResolver, spec compile.TypeSpec) (string, error)
- func IsPointerType(t string) bool
- func IsStructType(spec compile.TypeSpec) bool
- func LintAcronym(key string) string
- func LowerPascal(str string) string
- func PascalCase(src string) string
- func PopulateQPSLevels(EndpointsBaseDir string, isEnabled bool) (map[string]int, error)
- func PrintGenLine(classType, className, instanceName, buildPath string, idx, count int)
- func ReflectInterface(projRoot string, pathSymbolMap map[string]string) (map[string]*model.Package, error)
- func UnmarshalEndpointFile(endpointFile string) (map[string]interface{}, error)
- func Unref(t string) string
- func WriteAndFormat(path string, data []byte) error
- type AssetProvider
- type BodyType
- type BuildGenerator
- type BuildResult
- type ClassConfig
- type ClassConfigBase
- type ClientIDLConfig
- type ClientMeta
- type ClientSpec
- type ClientTestFixture
- type CustomClientConfig
- type Dependencies
- type EndpointClassConfig
- type EndpointCollectionMeta
- type EndpointConfig
- type EndpointGenerator
- type EndpointMeta
- type EndpointSpec
- func (e *EndpointSpec) EndpointTestConfigPath() string
- func (e *EndpointSpec) SetDownstream(clientModules []*ClientSpec, h *PackageHelper) error
- func (e *EndpointSpec) TargetEndpointPath(serviceName string, methodName string) string
- func (e *EndpointSpec) TargetEndpointTestPath(serviceName string, methodName string) string
- type EndpointTestFixture
- type EndpointTestMeta
- type ErrorSkipCodeGen
- type ExceptionSpec
- type FieldAssignment
- type FieldMapperEntry
- type Fixture
- type FixtureBlob
- type FixtureBody
- type FixtureHTTPRequest
- type FixtureHTTPResponse
- type FixtureHeaders
- type FixtureRequest
- type FixtureResponse
- type GRPCClientConfig
- type GatewayServiceGenerator
- type GoPackageImport
- type HTTPClientConfig
- type HTTPMethodType
- type HeaderFieldInfo
- type HeaderPropagator
- type IgnorePopulateSpecStageErr
- type LineBuilder
- type MethodSpec
- type MiddlewareConfig
- type MiddlewareConfigConfig
- type MiddlewareGenerator
- type MiddlewareSpec
- type MockgenBin
- type ModuleClass
- type ModuleClassConfig
- type ModuleDependency
- type ModuleInstance
- type ModuleSpec
- type ModuleSystem
- func NewDefaultModuleSystem(h *PackageHelper, selectiveBuilding bool, hooks ...PostGenHook) (*ModuleSystem, error)
- func NewDefaultModuleSystemWithMockHook(h *PackageHelper, clientsMock bool, workflowMock bool, serviceMock bool, ...) (*ModuleSystem, error)
- func NewModuleSystem(moduleSearchPaths map[string][]string, defaultDependencies map[string][]string, ...) *ModuleSystem
- func (system *ModuleSystem) Build(packageRoot string, baseDirectory string, physicalGenDir string, ...) error
- func (system *ModuleSystem) GenerateBuild(packageRoot string, baseDirectory string, targetGenDir string, options Options) (map[string][]*ModuleInstance, error)deprecated
- func (system *ModuleSystem) IncrementalBuild(packageRoot, baseDirectory, targetGenDir string, instances []ModuleDependency, ...) (map[string][]*ModuleInstance, error)
- func (system *ModuleSystem) RegisterClass(class ModuleClass) error
- func (system *ModuleSystem) RegisterClassType(className string, classType string, generator BuildGenerator) error
- func (system *ModuleSystem) ResolveModules(packageRoot string, baseDirectory string, targetGenDir string, options Options) (map[string][]*ModuleInstance, error)
- type Options
- type PackageHelper
- func (p PackageHelper) CodeGenTargetPath() string
- func (p PackageHelper) ConfigRoot() string
- func (p PackageHelper) DefaultHeaders() []string
- func (p PackageHelper) DefaultMiddlewareSpecs() map[string]*MiddlewareSpec
- func (p PackageHelper) DeputyReqHeader() string
- func (p PackageHelper) EndpointTestConfigPath(serviceName, methodName string) string
- func (p PackageHelper) GenCodePackage() map[string]string
- func (p PackageHelper) GetModuleIdlSubDir(isEndpoint bool) string
- func (p PackageHelper) GoGatewayPackageName() string
- func (p PackageHelper) IdlPath() string
- func (p PackageHelper) MiddlewareSpecs() map[string]*MiddlewareSpec
- func (p PackageHelper) PackageRoot() string
- func (p PackageHelper) TargetClientsInitPath() string
- func (p PackageHelper) TargetEndpointsRegisterPath() string
- func (p PackageHelper) TypeFullName(typeSpec compile.TypeSpec) (string, error)
- func (p PackageHelper) TypeImportPath(idlFile string) (string, error)
- func (p PackageHelper) TypePackageName(idlFile string) (string, error)
- type PackageHelperOptions
- type PackageInfo
- type PackageNameResolver
- type PathSegment
- type PostGenHook
- type ProtoMessage
- type ProtoModule
- type ProtoRPC
- type ProtoService
- type ProtocalType
- type ServiceSpec
- type ServiceSpecs
- type Services
- type SpecProvider
- type StatusCode
- type StructMeta
- type StructSpec
- type TChannelClientConfig
- type Template
- type TypeConverter
- type TypedHeader
Constants ¶
const ( // SingleModule defines a module class type that has 1 directory SingleModule moduleClassType = iota // MultiModule defines a module class type with multiple nested directories MultiModule moduleClassType = iota )
const ( // AntHTTPReqDefBoxed annotates a method so that the genereted method takes // generated argument directly instead of a struct that warps the argument. // The annotated method should have one and only one argument. AntHTTPReqDefBoxed = "%s.http.req.def" )
const CustomTemplate = "customTemplate"
CustomTemplate custom template representation
Variables ¶
var CommonInitialisms = map[string]bool{ "ACL": true, "API": true, "ASCII": true, "CPU": true, "CSS": true, "DNS": true, "EOF": true, "GUID": true, "HTML": true, "HTTP": true, "HTTPS": true, "ID": true, "IP": true, "JSON": true, "LHS": true, "OS": true, "QPS": true, "RAM": true, "RHS": true, "RPC": true, "SLA": true, "SMTP": true, "SQL": true, "SSH": true, "TCP": true, "TLS": true, "TTL": true, "UDP": true, "UI": true, "UID": true, "UUID": true, "URI": true, "URL": true, "UTF8": true, "VM": true, "XML": true, "XMPP": true, "XSRF": true, "XSS": true, }
CommonInitialisms is taken from https://github.com/golang/lint/blob/206c0f020eba0f7fbcfbc467a5eb808037df2ed6/lint.go#L731
Functions ¶
func CamelToSnake ¶
CamelToSnake converts a given string to snake case, based on https://github.com/serenize/snaker/blob/master/snaker.go
func ExecuteDefaultOrCustomTemplate ¶ added in v1.2.1
func ExecuteDefaultOrCustomTemplate( defaultTemplateName string, defaultTemplates *Template, customTemplates *Template, config map[string]interface{}, tplData interface{}, packageHelper *PackageHelper, ) (ret []byte, rErr error)
ExecuteDefaultOrCustomTemplate verify and execute a default or custom template
func FindClientsWithFixture ¶
func FindClientsWithFixture(instance *ModuleInstance) (map[string]string, error)
FindClientsWithFixture finds the given module's dependent clients that have fixture config
func FormatGoFile ¶
FormatGoFile reformat the go file imports
func GenerateDependencyStruct ¶
func GenerateDependencyStruct( instance *ModuleInstance, packageHelper *PackageHelper, template *Template, ) ([]byte, error)
GenerateDependencyStruct generates a module struct with placeholders for the instance module based on the defined dependency configuration
func GenerateInitializer ¶
func GenerateInitializer( instance *ModuleInstance, packageHelper *PackageHelper, template *Template, ) ([]byte, error)
GenerateInitializer generates a file that initializes a module fully recursively, i.e. by initializing all of its dependencies in the correct order
func GetClientQPSLevels ¶ added in v1.0.0
func GetClientQPSLevels(qpsLevels map[string]int, methods map[string]string, clientID string) map[string]string
GetClientQPSLevels gets mapping from client's circuit breaker name to qps level
func GetListOfAllFilesInEndpointDir ¶ added in v1.0.0
GetListOfAllFilesInEndpointDir gets all the endpoint config files takes empty filesList array as parameter to add to during recursion
func GoCustomType ¶ added in v0.4.3
func GoCustomType(p PackageNameResolver, spec compile.TypeSpec) (string, error)
GoCustomType returns the user-defined Go type with its importing package.
func GoReferenceType ¶
func GoReferenceType(p PackageNameResolver, spec compile.TypeSpec) (string, error)
GoReferenceType returns the Go reference type string representation for the given thrift type. for types like slice and map that are already of reference type, it returns the result of GoType; for struct type, it returns the pointer of the result of GoType.
func GoType ¶
func GoType(p PackageNameResolver, spec compile.TypeSpec) (string, error)
GoType returns the Go type string representation for the given thrift type.
func IsPointerType ¶ added in v0.2.0
IsPointerType determines if the passed in string is a string for a pointer
func IsStructType ¶
IsStructType returns true if the given thrift type is struct, false otherwise.
func LintAcronym ¶
LintAcronym correct the naming for initialisms
func LowerPascal ¶ added in v0.4.3
LowerPascal is Pascal with first char lower
func PascalCase ¶
PascalCase converts the given string to pascal case
func PopulateQPSLevels ¶ added in v1.0.0
PopulateQPSLevels loops through endpoint dir and gets qps levels
func PrintGenLine ¶
PrintGenLine prints the module generation process to stdout
func ReflectInterface ¶
func ReflectInterface(projRoot string, pathSymbolMap map[string]string) (map[string]*model.Package, error)
ReflectInterface uses reflection to obtain interface information for each path symbol pair in the pathSympolMap projRoot is the root dir where mockgen is installed as a vendor package
func UnmarshalEndpointFile ¶ added in v1.0.0
UnmarshalEndpointFile unmarshals endpoint file into config
func WriteAndFormat ¶
WriteAndFormat writes the data (Go code) to given file path, creates path if it does not exist and formats the file using gofmt
Types ¶
type AssetProvider ¶
type AssetProvider interface { // AssetNames returns a list of named assets available AssetNames() []string // Asset returns the bytes for a provided asset name Asset(string) ([]byte, error) }
AssetProvider provides access to template assets
type BuildGenerator ¶
type BuildGenerator interface { Generate( instance *ModuleInstance, ) (*BuildResult, error) }
BuildGenerator provides a function to generate a module instance build artifact from its configuration as part of a build step. For example, an Endpoint module instance may generate endpoint handler code
type BuildResult ¶
type BuildResult struct { // Files contains a map of file names to file bytes to be written to the // module build directory Files map[string][]byte // Spec is an arbitrary type that can be used to share computed data // between dependencies Spec interface{} }
BuildResult is the result of running a module generator
type ClassConfig ¶ added in v0.2.0
type ClassConfig struct { ClassConfigBase `yaml:",inline" json:",inline"` // Dependencies is a map of class name to a list of instance names. This // infers the dependencies struct generated for the initializer Dependencies map[string][]string `yaml:"dependencies" json:"dependencies"` // The configuration map for this class instance. This depends on the // class name and class type, and is interpreted by each module generator. Config map[string]interface{} `yaml:"config" json:"config"` }
ClassConfig maps onto a YAML configuration for a class type
func NewClassConfig ¶ added in v0.2.0
func NewClassConfig(raw []byte) (*ClassConfig, error)
NewClassConfig unmarshals raw bytes into a ClassConfig struct or return an error if it cannot be unmarshaled into the struct
type ClassConfigBase ¶ added in v0.2.0
type ClassConfigBase struct { // Name is the class instance name used to identify the module as a // dependency. The combination of the class Name and this instance name // is unique. Name string `yaml:"name" json:"name"` // Type refers to the class type used to generate the dependency Type string `yaml:"type" json:"type"` // IsExportGenerated determines whether or not the export lives in // IsExportGenerated defaults to true if not set. IsExportGenerated *bool `yaml:"IsExportGenerated,omitempty" json:"IsExportGenerated"` // CustomInitialisation defaults to false if not set. CustomInitialisation *bool `yaml:"CustomInitialisation,omitempty" json:"CustomInitialisation"` // Owner is the Name of the class instance owner Owner string `yaml:"owner,omitempty"` // SelectiveBuilding allows the module to be built with subset of dependencies SelectiveBuilding bool `yaml:"selectiveBuilding,omitempty" json:"selectiveBuilding"` }
ClassConfigBase defines the shared data fields for all class configs. Configs of different classes can derive from this base struct by add a specific "config" field and "dependencies" field
type ClientIDLConfig ¶ added in v0.3.0
type ClientIDLConfig struct { ExposedMethods map[string]string `yaml:"exposedMethods" json:"exposedMethods" validate:"exposedMethods"` IDLFile string `yaml:"idlFile" json:"idlFile" validate:"nonzero"` IDLFileSha string `yaml:"idlFileSha,omitempty" json:"idlFileSha"` SidecarRouter string `yaml:"sidecarRouter" json:"sidecarRouter"` Fixture *Fixture `yaml:"fixture,omitempty" json:"fixture"` CustomInterface string `yaml:"customInterface,omitempty" json:"customInterface,omitempty"` }
ClientIDLConfig is the "config" field in the client-config.yaml for HTTP/TChannel/gRPC clients.
type ClientMeta ¶
type ClientMeta struct { Instance *ModuleInstance ExportName string ExportType string ClientID string IncludedPackages []GoPackageImport Services []*ServiceSpec ProtoServices []*ProtoService ExposedMethods map[string]string // client-method name to qps level (string) // if not qps level for method value is "default" QPSLevels map[string]string SidecarRouter string Fixture *Fixture DeputyReqHeader string }
ClientMeta ...
type ClientSpec ¶
type ClientSpec struct { // ModuleSpec holds the thrift module information ModuleSpec *ModuleSpec // JSONFile for this spec JSONFile string // Deprecated // YAMLFile for this spec YAMLFile string // ClientType, currently "http", "tchannel" and "custom" are supported ClientType string // If "custom" then where to import custom code from CustomImportPath string // If "custom" then this is where the interface to mock comes from CustomInterface string // The path to the client package import ImportPackagePath string // The globally unique package alias for the import ImportPackageAlias string // ExportName is the name that should be used when initializing the module // on a dependency struct. ExportName string // ExportType refers to the type returned by the module initializer ExportType string // ThriftFile, absolute path to thrift file ThriftFile string // ClientID, used for logging and metrics, must be lowercase // and use dashes. ClientID string // ClientName, PascalCase name of the client, the generated // `Clients` struct will contain a field of this name ClientName string // ExposedMethods is a map of exposed method name to thrift "$service::$method" // only the method values in this map are generated for the client ExposedMethods map[string]string // SidecarRouter indicates the client uses the given sidecar router to // to communicate with downstream service, it's not relevant to custom clients. SidecarRouter string }
ClientSpec holds information about each client in the gateway included its thriftFile and other meta info
type ClientTestFixture ¶
type ClientTestFixture struct { ClientID string `yaml:"clientId" json:"clientId"` ClientMethod string `yaml:"clientMethod" json:"clientMethod"` ClientRequest FixtureRequest `yaml:"clientRequest" json:"clientRequest"` // there's no difference between http or tchannel request ClientReqHeaders FixtureHeaders `yaml:"clientReqHeaders" json:"clientReqHeaders"` ClientResponse FixtureResponse `yaml:"clientResponse" json:"clientResponse"` ClientResHeaders FixtureHeaders `yaml:"clientResHeaders" json:"clientResHeaders"` }
ClientTestFixture saves mocked client request/response for an endpoint test.
type CustomClientConfig ¶ added in v0.2.0
type CustomClientConfig struct { ClassConfigBase `yaml:",inline" json:",inline"` Dependencies Dependencies `yaml:"dependencies" json:"dependencies"` Config *struct { Fixture *Fixture `yaml:"fixture" json:"fixture"` CustomImportPath string `yaml:"customImportPath" json:"customImportPath" validate:"nonzero"` CustomInterface string `yaml:"customInterface,omitempty" json:"customInterface,omitempty"` } `yaml:"config" json:"config" validate:"nonzero"` }
CustomClientConfig represents the config for a custom client.
func (*CustomClientConfig) NewClientSpec ¶ added in v0.2.0
func (c *CustomClientConfig) NewClientSpec( instance *ModuleInstance, h *PackageHelper) (*ClientSpec, error)
NewClientSpec creates a client spec from a http client module instance
type Dependencies ¶
type Dependencies struct {
Client []string `yaml:"client" json:"client"`
}
Dependencies lists all dependencies of a module
type EndpointClassConfig ¶
type EndpointClassConfig struct { ClassConfigBase `yaml:",inline" json:",inline"` Dependencies map[string][]string `yaml:"dependencies" json:"dependencies"` Config *EndpointConfig `yaml:"config" json:"config" validate:"nonzero"` }
EndpointClassConfig represents the specific config for an endpoint group. This is a downcast of the moduleClassConfig.
type EndpointCollectionMeta ¶
type EndpointCollectionMeta struct { Instance *ModuleInstance EndpointMeta []*EndpointMeta }
EndpointCollectionMeta saves information used to generate an initializer for a collection of endpoints
type EndpointConfig ¶ added in v0.2.0
type EndpointConfig struct { Ratelimit int32 `yaml:"rateLimit,omitempty" json:"rateLimit"` Endpoints []string `yaml:"endpoints" json:"endpoints"` }
EndpointConfig represent the "config" field of endpoint-config.yaml
type EndpointGenerator ¶
type EndpointGenerator struct {
// contains filtered or unexported fields
}
EndpointGenerator generates a group of zanzibar endpoints that proxy corresponding clients
func (*EndpointGenerator) ComputeSpec ¶ added in v0.2.0
func (g *EndpointGenerator) ComputeSpec( instance *ModuleInstance, ) (interface{}, error)
ComputeSpec computes the endpoint specs for a group of endpoints
func (*EndpointGenerator) Generate ¶
func (g *EndpointGenerator) Generate( instance *ModuleInstance, ) (*BuildResult, error)
Generate returns the endpoint build result, which contains a file per endpoint handler and a list of handler specs
type EndpointMeta ¶
type EndpointMeta struct { Instance *ModuleInstance Spec *EndpointSpec GatewayPackageName string IncludedPackages []GoPackageImport Method *MethodSpec ClientName string ClientID string ClientType string ClientMethodName string WorkflowPkg string ReqHeaders map[string]*TypedHeader IsClientlessEndpoint bool ReqHeadersKeys []string ReqRequiredHeadersKeys []string ResHeaders map[string]*TypedHeader ResHeadersKeys []string ResRequiredHeadersKeys []string TraceKey string DeputyReqHeader string DefaultHeaders []string }
EndpointMeta saves meta data used to render an endpoint.
type EndpointSpec ¶
type EndpointSpec struct { // ModuleSpec holds the thrift module info ModuleSpec *ModuleSpec `yaml:"-"` // YAMLFile for this endpoint spec YAMLFile string `yaml:"-"` // GoStructsFileName is where structs are generated GoStructsFileName string `yaml:"-"` // GoFolderName is the folder where all the endpoints // are generated. GoFolderName string `yaml:"-"` // GoPackageName is the package import path. GoPackageName string `yaml:"-"` // EndpointType, currently only "http" EndpointType string `yaml:"endpointType" validate:"nonzero"` // EndpointID, used in metrics and logging, lower case. EndpointID string `yaml:"endpointId" validate:"nonzero"` // HandleID, used in metrics and logging, lowercase. HandleID string `yaml:"handleId" validate:"nonzero"` // ThriftFile, the thrift file for this endpoint ThriftFile string `yaml:"thriftFile" validate:"nonzero"` // ThriftFileSha, the SHA of the thrift file for this endpoint ThriftFileSha string `yaml:"thriftFileSha,omitempty"` // ThriftMethodName, which thrift method to use. ThriftMethodName string `yaml:"thriftMethodName" validate:"nonzero"` // ThriftServiceName, which thrift service to use. ThriftServiceName string `yaml:"-"` // TestFixtures, meta data to generate tests, TestFixtures map[string]*EndpointTestFixture `yaml:"testFixtures,omitempty"` // Middlewares, meta data to add middlewares, Middlewares []MiddlewareSpec `yaml:"middlewares,omitempty"` // HeadersPropagate, a map from endpoint request headers to // client request fields. HeadersPropagate map[string]FieldMapperEntry `yaml:"-"` // ReqTransforms, a map from client request fields to endpoint // request fields that should override their values. ReqTransforms map[string]FieldMapperEntry `yaml:"-"` // RespTransforms, a map from endpoint response fields to client // response fields that should override their values. RespTransforms map[string]FieldMapperEntry `yaml:"-"` // DummyReqTransforms is used to transform a clientless request to response mapping DummyReqTransforms map[string]FieldMapperEntry `yaml:"-"` // ErrTransforms is a map from endpoint exception fields to client exception fields // that should override their values // Note that this feature is not yet fully implemented in the stand-alone Zanzibar codebase ErrTransforms map[string]FieldMapperEntry `yaml:"-"` // ReqHeaders maps headers from server to client ReqHeaders map[string]*TypedHeader `yaml:"reqHeaderMap,omitempty"` // ResHeaders maps headers from client to server ResHeaders map[string]*TypedHeader `yaml:"resHeaderMap,omitempty"` // DefaultHeaders a slice of headers that are forwarded to downstream when available DefaultHeaders []string `yaml:"-"` // WorkflowType, either "httpClient" or "custom". // A httpClient workflow generates a http client Caller // A custom workflow just imports the custom code WorkflowType string `yaml:"workflowType" validate:"nonzero"` // If "custom" then where to import custom code from WorkflowImportPath string `yaml:"workflowImportPath"` // Config additional configs for the endpoint Config map[string]interface{} `yaml:"config,omitempty"` // if "httpClient", which client to call. ClientID string `yaml:"clientId,omitempty"` // if "httpClient", which client method to call. ClientMethod string `yaml:"clientMethod,omitempty"` // The client for this endpoint if httpClient or tchannelClient ClientSpec *ClientSpec `yaml:"-"` // IsClientlessEndpoint checks if the endpoint is clientless IsClientlessEndpoint bool `yaml:"-"` }
EndpointSpec holds information about each endpoint in the gateway including its thriftFile and meta data
func NewEndpointSpec ¶
func NewEndpointSpec( yamlFile string, h *PackageHelper, midSpecs map[string]*MiddlewareSpec, ) (*EndpointSpec, error)
NewEndpointSpec creates an endpoint spec from a yaml file.
func (*EndpointSpec) EndpointTestConfigPath ¶
func (e *EndpointSpec) EndpointTestConfigPath() string
EndpointTestConfigPath generates a filepath for each endpoint test config
func (*EndpointSpec) SetDownstream ¶
func (e *EndpointSpec) SetDownstream( clientModules []*ClientSpec, h *PackageHelper, ) error
SetDownstream configures the downstream client for this endpoint spec
func (*EndpointSpec) TargetEndpointPath ¶
func (e *EndpointSpec) TargetEndpointPath( serviceName string, methodName string, ) string
TargetEndpointPath generates a filepath for each endpoint method
func (*EndpointSpec) TargetEndpointTestPath ¶
func (e *EndpointSpec) TargetEndpointTestPath( serviceName string, methodName string, ) string
TargetEndpointTestPath generates a filepath for each endpoint test
type EndpointTestFixture ¶
type EndpointTestFixture struct { TestName string `yaml:"testName" json:"testName"` EndpointID string `yaml:"endpointId" json:"endpointId"` HandleID string `yaml:"handleId" json:"handleId"` EndpointRequest FixtureRequest `yaml:"endpointRequest" json:"endpointRequest"` // there's no difference between http or tchannel request EndpointReqHeaders FixtureHeaders `yaml:"endpointReqHeaders" json:"endpointReqHeaders"` EndpointResponse FixtureResponse `yaml:"endpointResponse" json:"endpointResponse"` EndpointResHeaders FixtureHeaders `yaml:"endpointResHeaders" json:"endpointResHeaders"` ClientTestFixtures map[string]*ClientTestFixture `yaml:"clientTestFixtures" json:"clientTestFixtures"` TestServiceName string `yaml:"testServiceName" json:"testServiceName"` // The service module that mounts the endpoint }
EndpointTestFixture saves mocked requests/responses for an endpoint test.
type EndpointTestMeta ¶
type EndpointTestMeta struct { Instance *ModuleInstance Method *MethodSpec TestFixtures map[string]*EndpointTestFixture `yaml:"testFixtures" json:"testFixtures"` ReqHeaders map[string]*TypedHeader ResHeaders map[string]*TypedHeader ClientName string ClientID string RelativePathToRoot string IncludedPackages []GoPackageImport }
EndpointTestMeta saves meta data used to render an endpoint test.
type ErrorSkipCodeGen ¶ added in v0.6.0
type ErrorSkipCodeGen struct {
IDLFile string
}
ErrorSkipCodeGen when thrown modules can be skipped building without failing code gen
func (*ErrorSkipCodeGen) Error ¶ added in v0.6.0
func (e *ErrorSkipCodeGen) Error() string
Error when thrown modules can be skipped building without failing code gen
type ExceptionSpec ¶
type ExceptionSpec struct { StructSpec StatusCode StatusCode IsBodyDisallowed bool }
ExceptionSpec contains information about thrift exceptions
type FieldAssignment ¶
type FieldAssignment struct { From *compile.FieldSpec FromIdentifier string To *compile.FieldSpec ToIdentifier string TypeCast string ExtraNilCheck bool }
FieldAssignment is responsible to generate an assignment
func (*FieldAssignment) Generate ¶
func (f *FieldAssignment) Generate(indent string, uninitialized map[string]*fieldStruct, prevKeyPrefixes []string, useRecurGen bool) string
Generate generates assignment
func (*FieldAssignment) IsTransform ¶
func (f *FieldAssignment) IsTransform() bool
IsTransform returns true if field assignment is not proxy
type FieldMapperEntry ¶
type FieldMapperEntry struct { QualifiedName string // Field *compile.FieldSpec Override bool // contains filtered or unexported fields }
FieldMapperEntry defines a source field and optional arguments converting and overriding fields.
type Fixture ¶
type Fixture struct { // ImportPath is the package where the user-defined Fixture global variable is contained. // The Fixture object defines, for a given client, the standardized list of fixture scenarios for that client ImportPath string `yaml:"importPath" json:"importPath" validate:"nonzero"` // Scenarios is a map from zanzibar's exposed method name to a list of user-defined fixture scenarios for a client Scenarios map[string][]string `yaml:"scenarios" json:"scenarios"` }
Fixture specifies client fixture import path and all scenarios
type FixtureBlob ¶
type FixtureBlob map[string]interface{}
FixtureBlob implements default string used for (http | tchannel) request/response
func (*FixtureBlob) String ¶
func (fb *FixtureBlob) String() string
String convert FixtureBlob to string
type FixtureBody ¶
type FixtureBody struct { BodyType BodyType `yaml:"bodyType,omitempty" json:"bodyType,omitempty"` BodyString string `yaml:"bodyString,omitempty" json:"bodyString,omitempty"` // set BodyString if response body is string BodyJSON *FixtureBlob `yaml:"bodyJson,omitempty" json:"bodyJson,omitempty"` // set Body if response body is object }
FixtureBody is used to create http body in test fixtures
func (*FixtureBody) String ¶
func (fb *FixtureBody) String() string
String convert FixtureBody to string This String() panics inside if type and value mismatch during unmarshal because template cannot handle errors
type FixtureHTTPRequest ¶
type FixtureHTTPRequest struct { Method HTTPMethodType `yaml:"method,omitempty" json:"method,omitempty"` Body *FixtureBody `yaml:"body,omitempty" json:"body,omitempty"` }
FixtureHTTPRequest is test fixture for client/endpoint request
type FixtureHTTPResponse ¶
type FixtureHTTPResponse struct { StatusCode int `yaml:"statusCode" json:"statusCode"` Body *FixtureBody `yaml:"body,omitempty" json:"body,omitempty"` }
FixtureHTTPResponse is test fixture for http response
type FixtureHeaders ¶ added in v0.2.0
type FixtureHeaders map[string]interface{}
FixtureHeaders implements default string used for headers
type FixtureRequest ¶
type FixtureRequest struct { RequestType ProtocalType `yaml:"requestType" json:"requestType"` HTTPRequest *FixtureHTTPRequest `yaml:"httpRequest,omitempty" json:"httpRequest,omitempty"` TChannelRequest FixtureBlob `yaml:"tchannelRequest,omitempty" json:"tchannelRequest,omitempty"` }
FixtureRequest is test fixture for client/endpoint request
func (*FixtureRequest) Body ¶
func (fr *FixtureRequest) Body() string
Body returns the string representation of FixtureRequest
type FixtureResponse ¶
type FixtureResponse struct { ResponseType ProtocalType `yaml:"responseType" json:"responseType"` HTTPResponse *FixtureHTTPResponse `yaml:"httpResponse,omitempty" json:"httpResponse,omitempty"` TChannelResponse FixtureBlob `yaml:"tchannelResponse,omitempty" json:"tchannelResponse,omitempty"` }
FixtureResponse is test fixture for client/endpoint response
func (*FixtureResponse) Body ¶
func (fr *FixtureResponse) Body() string
Body returns the string representation of FixtureResponse
type GRPCClientConfig ¶ added in v0.3.0
type GRPCClientConfig struct { ClassConfigBase `yaml:",inline" json:",inline"` Dependencies Dependencies `yaml:"dependencies,omitempty" json:"dependencies"` Config *ClientIDLConfig `yaml:"config" json:"config" validate:"nonzero"` }
GRPCClientConfig represents the "config" field for a gRPC client-config.yaml.
func (*GRPCClientConfig) NewClientSpec ¶ added in v0.4.3
func (c *GRPCClientConfig) NewClientSpec( instance *ModuleInstance, h *PackageHelper, ) (*ClientSpec, error)
NewClientSpec creates a client spec from a client module instance
type GatewayServiceGenerator ¶
type GatewayServiceGenerator struct {
// contains filtered or unexported fields
}
GatewayServiceGenerator generates an entry point for a single service as a main.go that bootstraps the service and its dependencies
func NewGatewayServiceGenerator ¶
func NewGatewayServiceGenerator(t *Template, h *PackageHelper) *GatewayServiceGenerator
NewGatewayServiceGenerator creates a new gateway service generator.
func (*GatewayServiceGenerator) ComputeSpec ¶ added in v0.2.0
func (generator *GatewayServiceGenerator) ComputeSpec( instance *ModuleInstance, ) (interface{}, error)
ComputeSpec computes the spec for a gateway
func (*GatewayServiceGenerator) Generate ¶
func (generator *GatewayServiceGenerator) Generate(instance *ModuleInstance) (*BuildResult, error)
Generate returns the gateway build result, which contains the service and service test main files, and no spec
type GoPackageImport ¶
GoPackageImport ...
type HTTPClientConfig ¶ added in v0.2.0
type HTTPClientConfig struct { ClassConfigBase `yaml:",inline" json:",inline"` Dependencies Dependencies `yaml:"dependencies,omitempty" json:"dependencies"` Config *ClientIDLConfig `yaml:"config" json:"config" validate:"nonzero"` }
HTTPClientConfig represents the "config" field for a HTTP client-config.yaml
func (*HTTPClientConfig) NewClientSpec ¶ added in v0.2.0
func (c *HTTPClientConfig) NewClientSpec( instance *ModuleInstance, h *PackageHelper) (*ClientSpec, error)
NewClientSpec creates a client spec from a client module instance
type HeaderFieldInfo ¶
HeaderFieldInfo contains information about where to store the string from headers into the request/response body.
type HeaderPropagator ¶
type HeaderPropagator struct { LineBuilder Helper PackageNameResolver }
HeaderPropagator generates function propagates endpoint request headers to client request body
func NewHeaderPropagator ¶
func NewHeaderPropagator(h PackageNameResolver) *HeaderPropagator
NewHeaderPropagator returns an instance of HeaderPropagator
func (*HeaderPropagator) Propagate ¶
func (hp *HeaderPropagator) Propagate( headers []string, toFields []*compile.FieldSpec, fieldMap map[string]FieldMapperEntry, ) error
Propagate assigns header value to downstream client request fields based on fieldMap
type IgnorePopulateSpecStageErr ¶ added in v0.6.0
type IgnorePopulateSpecStageErr struct {
Err error
}
IgnorePopulateSpecStageErr when thrown modules can be skipped building while populating spec
func (*IgnorePopulateSpecStageErr) Error ¶ added in v0.6.0
func (e *IgnorePopulateSpecStageErr) Error() string
Error when thrown modules can be skipped building without failing code gen
type LineBuilder ¶
type LineBuilder struct {
// contains filtered or unexported fields
}
LineBuilder struct just appends/builds lines.
func (*LineBuilder) GetLines ¶
func (l *LineBuilder) GetLines() []string
GetLines returns the lines in the line builder
type MethodSpec ¶
type MethodSpec struct { Name string HTTPMethod string // Used by edge gateway to generate endpoint. EndpointName string HTTPPath string PathSegments []PathSegment IsEndpoint bool // Statements for reading query parameters. ParseQueryParamGoStatements []string // Statements for writing query parameters WriteQueryParamGoStatements []string // Statements for reading request headers ReqHeaderGoStatements []string // Statements for reading request headers for clients ReqClientHeaderGoStatements []string // ResHeaderFields is a map of header name to a golang // field accessor expression used to read fields out // of the response body and place them into response headers ResHeaderFields map[string]HeaderFieldInfo // ReqHeaders needed, generated from "zanzibar.http.reqHeaders" ReqHeaders []string // ResHeaders needed, generated from "zanzibar.http.resHeaders" ResHeaders []string RequestType string ShortRequestType string ResponseType string ShortResponseType string OKStatusCode StatusCode Exceptions []ExceptionSpec ExceptionsByStatusCode map[int][]ExceptionSpec ExceptionsIndex map[string]ExceptionSpec ValidStatusCodes []int // Fully qualified field type of the unboxed field BoxedRequestType string // Unboxed field name BoxedRequestName string // Additional struct generated from the bundle of request args. RequestBoxed bool // Thrift service name the method belongs to. ThriftService string // The thriftrw-generated go package name GenCodePkgName string // Whether the method needs annotation or not. WantAnnot bool // The thriftrw compiled spec, used to extract type information CompiledThriftSpec *compile.FunctionSpec // The downstream service method set by endpoint config Downstream *ModuleSpec // the downstream service name DownstreamService string // The downstream method spec for the endpoint DownstreamMethod *MethodSpec // Statements for converting request types ConvertRequestGoStatements []string // Statements for converting response types ConvertResponseGoStatements []string // Statements for converting Clientless request types ConvertClientlessRequestGoStatements []string // Statements for propagating headers to client requests PropagateHeadersGoStatements []string // Statements for reading data out of url params (server) RequestParamGoStatements []string // contains filtered or unexported fields }
MethodSpec specifies all needed parts to generate code for a method in service.
func NewMethod ¶
func NewMethod( thriftFile string, funcSpec *compile.FunctionSpec, packageHelper *PackageHelper, wantAnnot bool, isEndpoint bool, thriftService string, ) (*MethodSpec, error)
NewMethod creates new method specification.
func (*MethodSpec) RefResponse ¶
func (ms *MethodSpec) RefResponse(respVar string) string
RefResponse prepends the response variable with '&' if it is not of reference type It is used to construct the `Success` field of the `$service_$method_Result` struct generated by thriftrw, which is always of reference type.
type MiddlewareConfig ¶
type MiddlewareConfig struct { ClassConfigBase `yaml:",inline" json:",inline"` Dependencies *Dependencies `yaml:"dependencies,omitempty" json:"dependencies,omitempty"` Config *MiddlewareConfigConfig `yaml:"config" json:"config"` }
MiddlewareConfig represents configuration for a middleware as is written in the yaml file
func (*MiddlewareConfig) Validate ¶
func (mid *MiddlewareConfig) Validate(configDirName string) error
Validate the config spec attributes
type MiddlewareConfigConfig ¶
type MiddlewareConfigConfig struct { OptionsSchemaFile string `yaml:"schema" json:"schema"` ImportPath string `yaml:"path" json:"path"` }
MiddlewareConfigConfig is the inner config object as prescribed by module_system yaml conventions
type MiddlewareGenerator ¶
type MiddlewareGenerator struct {
// contains filtered or unexported fields
}
MiddlewareGenerator generates a group of zanzibar endpoints that proxy corresponding clients
func (*MiddlewareGenerator) ComputeSpec ¶ added in v0.2.0
func (g *MiddlewareGenerator) ComputeSpec( instance *ModuleInstance, ) (interface{}, error)
ComputeSpec computes the spec for a middleware
func (*MiddlewareGenerator) Generate ¶
func (g *MiddlewareGenerator) Generate( instance *ModuleInstance, ) (*BuildResult, error)
Generate returns the endpoint build result, which contains a file per endpoint handler and a list of handler specs
type MiddlewareSpec ¶
type MiddlewareSpec struct { // The middleware package name. Name string `yaml:"name"` // Middleware specific configuration options. Options map[string]interface{} `yaml:"options"` // Options pretty printed for template initialization PrettyOptions map[string]string // Module Dependencies, clients etc. Dependencies *Dependencies // Go Import Path for MiddlewareHandle implementation ImportPath string // Location of yaml Schema file for the configured endpoint options OptionsSchemaFile string }
MiddlewareSpec holds information about each middleware at the endpoint
type MockgenBin ¶
type MockgenBin struct {
// contains filtered or unexported fields
}
MockgenBin is a struct abstracts the mockgen binary built from mockgen package in vendor
func NewMockgenBin ¶
func NewMockgenBin(h *PackageHelper, t *Template) (*MockgenBin, error)
NewMockgenBin builds the mockgen binary from vendor directory
func (MockgenBin) AugmentMockWithFixture ¶
func (m MockgenBin) AugmentMockWithFixture(pkg *model.Package, f *Fixture, intf string) ([]byte, []byte, error)
AugmentMockWithFixture generates mocks with fixture for the interface in the given package
type ModuleClass ¶
type ModuleClass struct { Name string NamePlural string ClassType moduleClassType DependsOn []string DependedBy []string // contains filtered or unexported fields }
ModuleClass defines a module class in the build configuration directory. THis could be something like an Endpoint class which contains multiple endpoint configurations, or a Lib class, that is itself a module instance
type ModuleClassConfig ¶
type ModuleClassConfig struct { ClassConfigBase `yaml:",inline" json:",inline"` Config interface{} `yaml:"config" json:"config"` }
ModuleClassConfig represents the generic YAML config for all modules. This will be provided by the module package.
type ModuleDependency ¶
type ModuleDependency struct { // ClassName is the name of the class as defined in the module system ClassName string // InstanceName is the name of the dependency instance as configu InstanceName string }
ModuleDependency defines a module instance required by another instance
type ModuleInstance ¶
type ModuleInstance struct { // PackageInfo is the name for the generated module instance PackageInfo *PackageInfo // ClassName is the name of the class as defined in the module system ClassName string // ClassType is the type of the class as defined in the module system ClassType string // BaseDirectory is the absolute path to module system system top level // directory BaseDirectory string // Directory is the relative instance directory Directory string // InstanceName is the name of the instance as configured in the instance's // YAML/JSON file InstanceName string // Config is a reference to the instance "config" key in the instances YAML // file. Config map[string]interface{} // Dependencies is a list of dependent modules as defined in the instances // YAML file Dependencies []ModuleDependency // Resolved dependencies is a list of direct dependent modules after processing // (fully resolved) ResolvedDependencies map[string][]*ModuleInstance // Recursive dependencies is a list of dependent modules and all of their // dependencies, i.e. the full tree of dependencies for this module. Each // class list is sorted for initialization order RecursiveDependencies map[string][]*ModuleInstance // DependencyOrder is the bottom to top order in which the recursively // resolved dependency class names can depend on each other DependencyOrder []string // The JSONFileName is file name of the instance JSON file JSONFileName string // Deprecated // The YAMLFileName is file name of the instance YAML file YAMLFileName string // JSONFileRaw is the raw JSON file read as bytes used for future parsing JSONFileRaw []byte // Deprecated // YAMLFileRaw is the raw YAML file read as bytes used for future parsing YAMLFileRaw []byte // SelectiveBuilding allows the module to be built with subset of dependencies SelectiveBuilding bool // QPSLevels is map of circuit breaker name to qps level for all circuit breakers QPSLevels map[string]int // CustomTemplates if using custom templates. we can write collection of custom templates that can be passed to zanzibar CustomTemplates *Template // contains filtered or unexported fields }
ModuleInstance is a configured module inside a module class directory. For example, this could be
ClassName: "Endpoint, ClassType: "http", BaseDirectory "/path/to/service/base/" Directory: "clients/health/" InstanceName: "health",
func (*ModuleInstance) AsModuleDependency ¶ added in v0.3.0
func (instance *ModuleInstance) AsModuleDependency() ModuleDependency
AsModuleDependency creates an equivalent ModuleDependency object for this instance
func (*ModuleInstance) GeneratedSpec ¶
func (instance *ModuleInstance) GeneratedSpec() interface{}
GeneratedSpec returns the last spec result returned for the module instance
func (*ModuleInstance) String ¶ added in v0.3.0
func (instance *ModuleInstance) String() string
type ModuleSpec ¶
type ModuleSpec struct { // CompiledModule is the resolved module from thrift file // that will contain modules and typedefs not directly mounted on AST CompiledModule *compile.Module `json:"omitempty"` // Source thrift file to generate the code. ThriftFile string // Whether the ThriftFile should have annotations or not WantAnnot bool // Whether the module is for an endpoint vs downstream client IsEndpoint bool // Go package name, generated base on module name. PackageName string // Go client types file path, generated from thrift file. GoThriftTypesFilePath string // Generated imports IncludedPackages []GoPackageImport Services ServiceSpecs ProtoServices []*ProtoService }
ModuleSpec collects the service specifications from thrift file.
func NewModuleSpec ¶
func NewModuleSpec( thrift string, wantAnnot bool, isEndpoint bool, packageHelper *PackageHelper, ) (*ModuleSpec, error)
NewModuleSpec returns a specification for a thrift module
func NewProtoModuleSpec ¶ added in v0.4.3
func NewProtoModuleSpec(protoFile string, isEndpoint bool, h *PackageHelper) (*ModuleSpec, error)
NewProtoModuleSpec returns a specification for a proto module.
func (*ModuleSpec) AddImports ¶
func (ms *ModuleSpec) AddImports(module *compile.Module, packageHelper *PackageHelper) error
AddImports adds imported Go packages in ModuleSpec in alphabetical order.
func (*ModuleSpec) AddServices ¶
func (ms *ModuleSpec) AddServices(module *compile.Module, packageHelper *PackageHelper) error
AddServices adds services in ModuleSpec in alphabetical order of service names.
func (*ModuleSpec) SetDownstream ¶
func (ms *ModuleSpec) SetDownstream( e *EndpointSpec, h *PackageHelper, ) error
SetDownstream ...
type ModuleSystem ¶
type ModuleSystem struct {
// contains filtered or unexported fields
}
ModuleSystem defines the module classes and their type generators
func NewDefaultModuleSystem ¶
func NewDefaultModuleSystem( h *PackageHelper, selectiveBuilding bool, hooks ...PostGenHook, ) (*ModuleSystem, error)
NewDefaultModuleSystem creates a fresh instance of the default zanzibar module system (clients, endpoints, services)
func NewDefaultModuleSystemWithMockHook ¶
func NewDefaultModuleSystemWithMockHook( h *PackageHelper, clientsMock bool, workflowMock bool, serviceMock bool, configFile string, parallelizeFactor int, selectiveBuilding bool, hooks ...PostGenHook, ) (*ModuleSystem, error)
NewDefaultModuleSystemWithMockHook creates a fresh instance of the default zanzibar module system (clients, endpoints, services) with a post build hook to generate client and service mocks
func NewModuleSystem ¶
func NewModuleSystem( moduleSearchPaths map[string][]string, defaultDependencies map[string][]string, selectiveBuilding bool, postGenHook ...PostGenHook, ) *ModuleSystem
NewModuleSystem returns a new module system
func (*ModuleSystem) Build ¶ added in v0.3.0
func (system *ModuleSystem) Build(packageRoot string, baseDirectory string, physicalGenDir string, instance *ModuleInstance, options Options) error
Build invokes the generator for a module instance and optionally writes the files to disk
func (*ModuleSystem) GenerateBuild
deprecated
func (system *ModuleSystem) GenerateBuild( packageRoot string, baseDirectory string, targetGenDir string, options Options, ) (map[string][]*ModuleInstance, error)
GenerateBuild will, given a module system configuration directory and a target build directory, run the generators assigned to each type of module and write the generated output to the module build directory if commitChange
Deprecated: Use Build instead.
func (*ModuleSystem) IncrementalBuild ¶ added in v0.3.0
func (system *ModuleSystem) IncrementalBuild( packageRoot, baseDirectory, targetGenDir string, instances []ModuleDependency, resolvedModules map[string][]*ModuleInstance, options Options, ) (map[string][]*ModuleInstance, error)
IncrementalBuild is like Build but filtered to only the given module instances.
func (*ModuleSystem) RegisterClass ¶
func (system *ModuleSystem) RegisterClass(class ModuleClass) error
RegisterClass defines a class of module in the module system For example, an "Endpoint" class or a "Client" class
func (*ModuleSystem) RegisterClassType ¶
func (system *ModuleSystem) RegisterClassType( className string, classType string, generator BuildGenerator, ) error
RegisterClassType registers a type generator for a specific module class For example, the "http"" type generator for the "Endpoint"" class
func (*ModuleSystem) ResolveModules ¶
func (system *ModuleSystem) ResolveModules( packageRoot string, baseDirectory string, targetGenDir string, options Options, ) (map[string][]*ModuleInstance, error)
ResolveModules resolves the module instances from the config on disk Using the system class and type definitions, the class directories are walked, and a module instance is initialized for each identified module in the target directory.
type Options ¶ added in v1.1.0
type Options struct { EnableCustomInitialisation bool CommitChange bool QPSLevelsEnabled bool CustomTemplates *Template }
Options Provides the features that are enabled while generating the build.
type PackageHelper ¶
type PackageHelper struct {
// contains filtered or unexported fields
}
PackageHelper manages the mapping from idl file to generated type code and service code.
func NewPackageHelper ¶
func NewPackageHelper( packageRoot string, configRoot string, options *PackageHelperOptions, ) (*PackageHelper, error)
NewPackageHelper creates a package helper. packageRoot is the project root package path, configRoot is the project config dir path. options can be nil, in which case all optional settings for the package are set to default values.
func (PackageHelper) CodeGenTargetPath ¶
func (p PackageHelper) CodeGenTargetPath() string
CodeGenTargetPath returns the file path where the code should be generated.
func (PackageHelper) ConfigRoot ¶
func (p PackageHelper) ConfigRoot() string
ConfigRoot returns the service's absolute config root path
func (PackageHelper) DefaultHeaders ¶ added in v0.6.0
func (p PackageHelper) DefaultHeaders() []string
DefaultHeaders returns a list of headers that will always be forwarded when present in the incoming request.
func (PackageHelper) DefaultMiddlewareSpecs ¶ added in v0.3.0
func (p PackageHelper) DefaultMiddlewareSpecs() map[string]*MiddlewareSpec
DefaultMiddlewareSpecs returns a map of default middlewares
func (PackageHelper) DeputyReqHeader ¶
func (p PackageHelper) DeputyReqHeader() string
DeputyReqHeader returns the header name that will be checked to determine if a request should go to the deputy downstream client
func (PackageHelper) EndpointTestConfigPath ¶
func (p PackageHelper) EndpointTestConfigPath( serviceName, methodName string, ) string
EndpointTestConfigPath returns the path for the endpoint test configs
func (PackageHelper) GenCodePackage ¶ added in v0.3.0
func (p PackageHelper) GenCodePackage() map[string]string
GenCodePackage returns map of idl type to the file path of the idl generated code folder
func (PackageHelper) GetModuleIdlSubDir ¶ added in v0.6.0
func (p PackageHelper) GetModuleIdlSubDir(isEndpoint bool) string
GetModuleIdlSubDir returns subdir for idl per module
func (PackageHelper) GoGatewayPackageName ¶
func (p PackageHelper) GoGatewayPackageName() string
GoGatewayPackageName returns the name of the gateway package
func (PackageHelper) IdlPath ¶ added in v0.6.0
func (p PackageHelper) IdlPath() string
IdlPath returns the file path to the thrift idl folder
func (PackageHelper) MiddlewareSpecs ¶
func (p PackageHelper) MiddlewareSpecs() map[string]*MiddlewareSpec
MiddlewareSpecs returns a map of middlewares available
func (PackageHelper) PackageRoot ¶
func (p PackageHelper) PackageRoot() string
PackageRoot returns the service's root package name
func (PackageHelper) TargetClientsInitPath ¶
func (p PackageHelper) TargetClientsInitPath() string
TargetClientsInitPath returns where the clients init should go
func (PackageHelper) TargetEndpointsRegisterPath ¶
func (p PackageHelper) TargetEndpointsRegisterPath() string
TargetEndpointsRegisterPath returns where the endpoints register file should be written to
func (PackageHelper) TypeFullName ¶
func (p PackageHelper) TypeFullName(typeSpec compile.TypeSpec) (string, error)
TypeFullName returns the referred Go type name in generated code.
func (PackageHelper) TypeImportPath ¶
func (p PackageHelper) TypeImportPath(idlFile string) (string, error)
TypeImportPath returns the Go import path for types defined in a idlFile file.
func (PackageHelper) TypePackageName ¶
func (p PackageHelper) TypePackageName(idlFile string) (string, error)
TypePackageName returns the package name that defines the type.
type PackageHelperOptions ¶
type PackageHelperOptions struct { // relative path to the idl dir, defaults to "./idl" RelIdlRootDir string // subdir for idl per module ModuleIdlSubDir map[string]string // relative path to the target dir that will contain generated code, defaults to "./build" RelTargetGenDir string // relative path to the middleware config dir, defaults to "" RelMiddlewareConfigDir string // relative path to the default middleware config dir, defaults to "" RelDefaultMiddlewareConfigDir string // map of idl type to package path of the generated code // map should be keyed with idl file extension, e.g., .thrift, .proto GenCodePackage map[string]string // thrift http annotation prefix, defaults to "zanzibar" AnnotationPrefix string // copyright header in generated code, defaults to "" CopyrightHeader string // header key to redirect client requests to staging environment, defaults to "X-Zanzibar-Use-Staging" StagingReqHeader string // The default headers to forward with all requests when present DefaultHeaders []string // header key to redirect client requests to local environment, defaults to "x-deputy-forwarded" DeputyReqHeader string // header key to uniquely identifies request/response pair, defaults to "x-trace-id" TraceKey string // ModuleSearchPaths is a dictionary of glob patterns for folders that contain *-config.yaml files ModuleSearchPaths map[string][]string // DefaultDependencies is a dictionary of glob patterns for folders that contain default dependencies DefaultDependencies map[string][]string // key to read qps levels or not in the endpoint levels QPSLevelsEnabled bool // key to enable custom initialisation CustomInitialisationEnabled bool }
PackageHelperOptions set the optional configurations for the project package. Each field is optional, if not set, it is set to the corresponding default value.
func NewDefaultPackageHelperOptions ¶
func NewDefaultPackageHelperOptions() *PackageHelperOptions
NewDefaultPackageHelperOptions returns a new default PackageHelperOptions, all optional fields are set as default.
type PackageInfo ¶
type PackageInfo struct { // PackageName is the name of the generated package, and should be the same // as the package name used by any custom code in the config directory PackageName string // PackageAlias is the unique import alias for non-generated packages PackageAlias string // PackageRoot is the unique import root for non-generated packages PackageRoot string // GeneratedPackageAlias is the unique import alias for generated packages GeneratedPackageAlias string // GeneratedModulePackageAlias is the unique import alias for the module system's, // generated subpackage GeneratedModulePackageAlias string // PackagePath is the full package path for the non-generated code PackagePath string // GeneratedPackagePath is the full package path for the generated code GeneratedPackagePath string // GeneratedModulePackagePath is the full package path for the generated dependency // structs and initializers GeneratedModulePackagePath string // QualifiedInstanceName for this package. Pascal case name for this module. QualifiedInstanceName string // ExportName is the name on the module initializer function ExportName string // ExportType refers to the type returned by the module initializer ExportType string // InitializerName is the name of function that can fully initialize the // module and its dependencies InitializerName string // IsExportGenerated is true if the export type is provided by the // generated package, otherwise it is assumed that the export type resides // in the non-generated package IsExportGenerated bool // CustomInitialisation if CustomInitialisation is true it basically changes the // import path of the module. For e.g. if the import path of a module is // package import path: "github.com/uber/zanzibar/examples/example-gateway/build/clients/echo" // module import path: "github.com/uber/zanzibar/examples/example-gateway/build/clients/echo/module" // then with CustomInitialisation=true the new import path are // package import path: "github.com/uber/zanzibar/examples/example-gateway/clients/echo" // module import path: "github.com/uber/zanzibar/examples/example-gateway/clients/echo" // hence the new import path are outside of the build folder or generated code, giving developer control over // the constructors of the module. CustomInitialisation bool }
PackageInfo provides information about the package associated with a module instance.
func (*PackageInfo) ImportPackageAlias ¶
func (info *PackageInfo) ImportPackageAlias() string
ImportPackageAlias returns the correct package alias for referencing the module's exported type, depending on whether or not the export is generated
func (*PackageInfo) ImportPackagePath ¶
func (info *PackageInfo) ImportPackagePath() string
ImportPackagePath returns the correct package path for the module's exported type, depending on which package (generated or not) the type lives in
func (*PackageInfo) ModulePackageAlias ¶
func (info *PackageInfo) ModulePackageAlias() string
ModulePackageAlias returns the correct package path for the module's exported type, depending on which package (generated or not) the type lives in
func (*PackageInfo) ModulePackagePath ¶
func (info *PackageInfo) ModulePackagePath() string
ModulePackagePath returns the correct package path for the module's exported type, depending on which package (generated or not) the type lives in
type PackageNameResolver ¶
PackageNameResolver interface allows for resolving what the package name for a thrift file is. This depends on where the thrift-based structs are generated.
type PathSegment ¶
type PathSegment struct { Type string Text string BodyIdentifier string ParamName string Required bool }
PathSegment represents a part of the http path.
type PostGenHook ¶
type PostGenHook func(map[string][]*ModuleInstance) error
PostGenHook provides a way to do work after the build is generated, useful to augment the build, e.g. generate mocks after interfaces are generated
func ClientMockGenHook ¶
func ClientMockGenHook(h *PackageHelper, t *Template, parallelizeFactor int) (PostGenHook, error)
ClientMockGenHook returns a PostGenHook to generate client mocks
func ServiceMockGenHook ¶
func ServiceMockGenHook(h *PackageHelper, t *Template, configFile string) PostGenHook
ServiceMockGenHook returns a PostGenHook to generate service mocks
func WorkflowMockGenHook ¶
func WorkflowMockGenHook(h *PackageHelper, t *Template) PostGenHook
WorkflowMockGenHook returns a PostGenHook to generate endpoint workflow mocks
type ProtoMessage ¶ added in v0.4.3
type ProtoMessage struct {
Name string
}
ProtoMessage is an internal representation of a Proto Message.
type ProtoModule ¶ added in v0.4.3
ProtoModule is an internal representation of a parsed Proto file.
type ProtoRPC ¶ added in v0.4.3
type ProtoRPC struct { Name string Request *ProtoMessage Response *ProtoMessage }
ProtoRPC is an internal representation of Proto RPC method and its request/response types.
type ProtoService ¶ added in v0.4.3
ProtoService is an internal representation of Proto service and methods in that service.
type ServiceSpec ¶
type ServiceSpec struct { // Service name Name string // Source thrift file to generate the code. ThriftFile string // Whether the service should have annotations or not WantAnnot bool // Whether the service is for an endpoint vs downstream client IsEndpoint bool // List of methods/endpoints of the service Methods []*MethodSpec // thriftrw compile spec. CompileSpec *compile.ServiceSpec }
ServiceSpec specifies a service.
func NewServiceSpec ¶
func NewServiceSpec( spec *compile.ServiceSpec, wantAnnot bool, isEndpoint bool, packageHelper *PackageHelper, ) (*ServiceSpec, error)
NewServiceSpec creates a service specification from given thrift file path.
func (*ServiceSpec) NewMethod ¶
func (s *ServiceSpec) NewMethod( funcSpec *compile.FunctionSpec, packageHelper *PackageHelper, ) (*MethodSpec, error)
NewMethod creates new method specification.
type ServiceSpecs ¶ added in v0.6.5
type ServiceSpecs []*ServiceSpec
ServiceSpecs is a list of ServiceSpecs
func (ServiceSpecs) Len ¶ added in v0.6.5
func (a ServiceSpecs) Len() int
func (ServiceSpecs) Less ¶ added in v0.6.5
func (a ServiceSpecs) Less(i, j int) bool
func (ServiceSpecs) Swap ¶ added in v0.6.5
func (a ServiceSpecs) Swap(i, j int)
type SpecProvider ¶ added in v0.2.0
type SpecProvider interface { ComputeSpec( instance *ModuleInstance, ) (interface{}, error) }
SpecProvider is a generator that can provide a specification without running the build step.
type StatusCode ¶
StatusCode is for http status code with exception message.
type StructMeta ¶
type StructMeta struct { Instance *ModuleInstance Spec *ModuleSpec }
StructMeta saves information to generate an endpoint's thrift structs file
type StructSpec ¶
StructSpec specifies a Go struct to be generated.
type TChannelClientConfig ¶ added in v0.2.0
type TChannelClientConfig struct { ClassConfigBase `yaml:",inline" json:",inline"` Dependencies Dependencies `yaml:"dependencies,omitempty" json:"dependencies"` Config *ClientIDLConfig `yaml:"config" json:"config" validate:"nonzero"` }
TChannelClientConfig represents the "config" field for a TChannel client-config.yaml
func (*TChannelClientConfig) NewClientSpec ¶ added in v0.2.0
func (c *TChannelClientConfig) NewClientSpec( instance *ModuleInstance, h *PackageHelper) (*ClientSpec, error)
NewClientSpec creates a client spec from a client module instance
type Template ¶
type Template struct {
// contains filtered or unexported fields
}
Template generates code for edge gateway clients and edgegateway endpoints.
func GetDefaultOrCustomTemplate ¶ added in v1.2.1
func GetDefaultOrCustomTemplate(defaultTemplateName string, defaultTemplate *Template, customTemplate *Template, config map[string]interface{}, ) (string, *Template)
GetDefaultOrCustomTemplate verify and returns overridden template if present
func NewDefaultTemplate ¶
NewDefaultTemplate creates a bundle of templates.
func NewTemplate ¶
func NewTemplate( assetProvider AssetProvider, functionMap tmpl.FuncMap, ) (*Template, error)
NewTemplate returns a template helper for the provided asset collection
func (*Template) ExecTemplate ¶
func (t *Template) ExecTemplate( tplName string, tplData interface{}, pkgHelper *PackageHelper, buildTags ...string, ) (ret []byte, rErr error)
ExecTemplate executes the named templated, returning the generated bytes
type TypeConverter ¶
type TypeConverter struct { LineBuilder Helper PackageNameResolver // contains filtered or unexported fields }
TypeConverter can generate a function body that converts two thriftrw FieldGroups from one to another. It's assumed that the converted code operates on two variables, "in" and "out" and that both are a go struct.
func NewTypeConverter ¶
func NewTypeConverter(h PackageNameResolver, optionalEntries map[string]FieldMapperEntry) *TypeConverter
NewTypeConverter returns *TypeConverter (tc) @optionalEntries contains Entries that already set for tc fromFields entry set in @optionalEntries, tc will not raise error when this entry is required for toFields but missing from fromFields
func (*TypeConverter) GenStructConverter ¶
func (c *TypeConverter) GenStructConverter( fromFields []*compile.FieldSpec, toFields []*compile.FieldSpec, fieldMap map[string]FieldMapperEntry, ) error
GenStructConverter will add lines to the TypeConverter for mapping from one go struct to another based on two thriftrw.FieldGroups. fieldMap is a may from keys that are the qualified field path names for destination fields (sent to the downstream client) and the entries are source fields (from the incoming request)