client

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2022 License: Apache-2.0 Imports: 3 Imported by: 183

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	StdVerbGet      = "get"
	StdVerbBatchGet = "batchGet"
	StdVerbList     = "list"
	StdVerbWatch    = "watch"
	StdVerbSearch   = "search"
	StdVerbCreate   = "create"
	StdVerbUpdate   = "update"
	StdVerbDelete   = "delete"
)

standard verbs

Functions

This section is empty.

Types

type ApiDescriptor

type ApiDescriptor interface {
	// GetFullAPIName returns fully qualified name that is same as used as PREFIX in
	// grpc.UnaryStreamInfo (or stream equivalent) objects for all , for example
	// /goten.example.library.v1beta.BookService
	GetFullAPIName() string

	// GetProtoPkgName returns proto package where corresponding RPC service is defined,
	// for example "goten.example.library.v1beta"
	GetProtoPkgName() string

	// GetApiName returns Goten API name (GRPC service as defined in proto file), for example BookService
	GetApiName() string

	// GetServiceDomain returns domain of Goten service, as defined by field "name" in api-skeleton yaml file,
	// for example library.edgelq.com
	GetServiceDomain() string

	// GetServiceVersion returns version of Goten service, as defined by field "proto.package.currentVersion"
	// field in api-skeleton yaml file, for example "v1"
	GetServiceVersion() string

	// AllMethodDescriptors returns all method descriptors
	AllMethodDescriptors() []MethodDescriptor
}

ApiDescriptor allows writing code operating on Goten API without knowing exact type. It can be used to access all methods and their properties, use grpc.ClientConnInterface without knowing exact types. ApiDescriptor corresponds to single Goten-API service (represented by single GRPC proto definition) in specific proto file.

type MethodDescriptor

type MethodDescriptor interface {
	// NewEmptyClientMsg returns empty, freshly allocated client message for this method
	NewEmptyClientMsg() proto.Message

	// NewEmptyServerMsg returns empty, freshly allocated server message for this method
	NewEmptyServerMsg() proto.Message

	// IsUnary returns true if method is unary (IsClientStream = false and IsServerStream = false)
	IsUnary() bool

	// IsClientStream returns true if method has client streaming
	IsClientStream() bool

	// IsServerStream returns true if method has server streaming
	IsServerStream() bool

	// IsCollection returns true if method operates on resource collection
	IsCollection() bool

	// IsPlural return true if method operates on multiple resources
	IsPlural() bool

	// HasResource returns true if method has resource defined
	HasResource() bool

	// RequestHasResourceBody returns true if method contains resource body
	RequestHasResourceBody() bool

	// GetVerb returns verb of method, for example "list", "search"...
	GetVerb() string

	// GetMethodName returns RPC method name (as defied in proto file), for example ListBooks
	GetMethodName() string

	// GetFullMethodName returns fully qualified name that is same as used in grpc.UnaryStreamInfo
	// (or stream equivalent), for example /goten.example.library.v1beta.BookService/ListBooks
	GetFullMethodName() string

	// GetProtoPkgName returns proto package where method and corresponding RPC service is defined,
	// for example "goten.example.library.v1beta"
	GetProtoPkgName() string

	// GetApiName returns Goten API name (GRPC service as defined in proto file), for example BookService
	GetApiName() string

	// GetServiceDomain returns domain of Goten service, as defined by field "name" in api-skeleton yaml file,
	// for example library.edgelq.com
	GetServiceDomain() string

	// GetServiceVersion returns version of Goten service, as defined by field "proto.package.currentVersion"
	// field in api-skeleton yaml file, for example "v1"
	GetServiceVersion() string

	// GetApiDescriptor returns descriptor of service owning this method
	GetApiDescriptor() ApiDescriptor

	// GetResourceDescriptor returns descriptor of resource on which method operates (may be nil)
	GetResourceDescriptor() resource.Descriptor

	// GetClientMsgReflectHandle returns handle accessing common properties from client message
	GetClientMsgReflectHandle() MethodMsgHandle

	// GetServerMsgReflectHandle returns handle accessing common properties from server message
	GetServerMsgReflectHandle() MethodMsgHandle
}

MethodDescriptor allows writing code operating on Method without knowing exact input/output type or name. It also allows accessing common properties of a method.

type MethodMsgHandle

type MethodMsgHandle interface {
	// ExtractResourceName returns resource name from request/response objects. For example,
	// handle for Get<Resource>/Get<Resource>Request will return value "name". For
	// Create<Resource>/Create<Resource>Request, it will return value of "<resource>.name" field. For
	// Create<Resource>/<Resource> (response!) it will return value of "name" field.
	ExtractResourceName(msg proto.Message) resource.Name

	// ExtractResourceNames returns list of resource names from request/response objects. It will
	// be used for batchGet requests (field "names"!) or responses for List/Watch/Search queries.
	ExtractResourceNames(msg proto.Message) resource.NameList

	// ExtractCollectionName returns resource collection name from request/response objects (However,
	// at this moment we dont code-gen anything for responses - although if user provides "Override", then it can).
	ExtractCollectionName(msg proto.Message) resource.Name
}

MethodMsgHandle allows accessing common properties of a request/response object without knowing exact type. Goten provides basic code-gen for standard methods (and custom ones, as long as request has standard "name" or "parent" field in a root).

type Registry

type Registry struct {
	// contains filtered or unexported fields
}

Registry contains all known service descriptors and allows accessing them by domain name and version. It is responsibility of developer to import all resource packages in order to ensure their registration.

func GetRegistry

func GetRegistry() *Registry

GetRegistry returns global registry instance

func (*Registry) FindAllVersionsOfServiceDescriptors

func (r *Registry) FindAllVersionsOfServiceDescriptors(serviceDomain string) []ServiceDescriptor

func (*Registry) FindApiDescriptor

func (r *Registry) FindApiDescriptor(fullApiName string) ApiDescriptor

FindApiDescriptor gives API descriptor based on full api name, for example "/ntt.iam.v1alpha.ProjectService" - basically this is same as full method name from grpc.UnaryServerInfo or grpc.StreamServerInfo without method name and trailing '/'

func (*Registry) FindMethodDescriptor

func (r *Registry) FindMethodDescriptor(fullMethodName string) MethodDescriptor

FindMethodDescriptor gives method descriptor based on full method name, for example "/ntt.iam.v1alpha.ProjectService/ListProjects" - can be obtained from grpc.UnaryServerInfo or grpc.StreamServerInfo

func (*Registry) FindNewestVersionServiceDescriptor

func (r *Registry) FindNewestVersionServiceDescriptor(serviceDomain string) ServiceDescriptor

func (*Registry) FindVersionedServiceDescriptor

func (r *Registry) FindVersionedServiceDescriptor(serviceDomain, version string) ServiceDescriptor

func (*Registry) RegisterApiDescriptor

func (r *Registry) RegisterApiDescriptor(descriptor ApiDescriptor)

func (*Registry) RegisterMethodDescriptor

func (r *Registry) RegisterMethodDescriptor(descriptor MethodDescriptor)

func (*Registry) RegisterSvcDescriptor

func (r *Registry) RegisterSvcDescriptor(descriptor ServiceDescriptor)

type ServiceDescriptor

type ServiceDescriptor interface {
	// GetServiceDomain returns domain of Goten service, as defined by field "name" in api-skeleton yaml file,
	// for example library.edgelq.com
	GetServiceDomain() string

	// GetVersion returns version of Goten service, as defined by field "proto.package.currentVersion"
	// field in api-skeleton yaml file, for example "v1"
	GetVersion() string

	// GetNextVersion returns next version of Goten service, as defined by field "proto.package.nextVersion"
	// field in api-skeleton yaml file, for example "v1"
	GetNextVersion() string

	// AllResourceDescriptors returns descriptors for all owned resources
	AllResourceDescriptors() []resource.Descriptor

	// AllApiDescriptors returns descriptors for all owned APIs
	AllApiDescriptors() []ApiDescriptor

	// AllImportedServiceInfos returns information about all imported services.
	// Registry can be used to obtain proper descriptor, as long as it was imported
	// (We do not enforce all the imports in generated code)
	AllImportedServiceInfos() []ServiceImportInfo
}

ServiceDescriptor allows writing code operating on Goten Service without knowing exact type. It can be used to access all APIs/Methods, their properties, all resource types. ServiceDescriptor corresponds to service definition in api-skeleton file (one per version).

type ServiceImportInfo added in v0.4.39

type ServiceImportInfo struct {
	Domain  string
	Version string
}

Jump to

Keyboard shortcuts

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