Documentation
¶
Overview ¶
Package generic ...
Index ¶
- Variables
- func EnableSetFieldsForEmptyStruct(g Generic, mode SetFieldsForEmptyStructMode) error
- func GetSeqID(transBuff []byte) (int32, error)
- func ParseContent(path, content string, includes map[string]string, isAbsIncludePath bool) (*parser.Thrift, error)
- func ServiceInfoWithGeneric(g Generic) *serviceinfo.ServiceInfo
- func SetBinaryWithBase64(g Generic, enable bool) error
- func SetBinaryWithByteSlice(g Generic, enable bool) error
- func SetSeqID(seqID int32, transBuff []byte) error
- type Args
- type BidiStreamingServer
- type ClientStreamingServer
- type Closer
- type DescriptorProvider
- func NewThriftFileProvider(path string, includeDirs ...string) (DescriptorProvider, error)
- func NewThriftFileProviderWithDynamicGo(path string, includeDirs ...string) (DescriptorProvider, error)
- func NewThriftFileProviderWithDynamicgoWithOption(path string, opts []ThriftIDLProviderOption, includeDirs ...string) (DescriptorProvider, error)
- func NewThriftFileProviderWithOption(path string, opts []ThriftIDLProviderOption, includeDirs ...string) (DescriptorProvider, error)
- type Generic
- func BinaryPbGeneric(svcName, packageName string) Generic
- func BinaryThriftGeneric() Generic
- func BinaryThriftGenericV2(serviceName string) Generic
- func HTTPPbThriftGeneric(p DescriptorProvider, pbp PbDescriptorProvider) (Generic, error)
- func HTTPThriftGeneric(p DescriptorProvider, opts ...Option) (Generic, error)
- func JSONPbGeneric(p PbDescriptorProviderDynamicGo, opts ...Option) (Generic, error)
- func JSONThriftGeneric(p DescriptorProvider, opts ...Option) (Generic, error)
- func MapThriftGeneric(p DescriptorProvider) (Generic, error)
- func MapThriftGenericForJSON(p DescriptorProvider) (Generic, error)
- type GetMethodNameByRequestFunc
- type GetProviderOption
- type HTTPRequest
- type HTTPResponse
- type Method
- type Option
- type Options
- type PbContentProvider
- type PbDescriptorProvider
- type PbDescriptorProviderDynamicGo
- func NewPbContentProviderWithDynamicGo(ctx context.Context, options dproto.Options, mainPath, mainContent string, ...) (PbDescriptorProviderDynamicGo, error)
- func NewPbFileProviderWithDynamicGo(main string, ctx context.Context, options dproto.Options, importDirs ...string) (PbDescriptorProviderDynamicGo, error)
- type PbFileProviderWithDynamicGo
- type ProviderOption
- type Result
- type ServerStreamingServer
- type Service
- type ServiceV2
- type SetFieldsForEmptyStructMode
- type ThriftContentProvider
- type ThriftContentWithAbsIncludePathProvider
- func NewThriftContentWithAbsIncludePathProvider(mainIDLPath string, includes map[string]string, ...) (*ThriftContentWithAbsIncludePathProvider, error)
- func NewThriftContentWithAbsIncludePathProviderWithDynamicGo(mainIDLPath string, includes map[string]string, ...) (*ThriftContentWithAbsIncludePathProvider, error)
- func (p *ThriftContentWithAbsIncludePathProvider) Close() error
- func (p *ThriftContentWithAbsIncludePathProvider) Option() ProviderOption
- func (p *ThriftContentWithAbsIncludePathProvider) Provide() <-chan *descriptor.ServiceDescriptor
- func (p *ThriftContentWithAbsIncludePathProvider) UpdateIDL(mainIDLPath string, includes map[string]string) error
- type ThriftIDLProviderOption
- type WithCodec
Constants ¶
This section is empty.
Variables ¶
var ( DefaultHTTPDynamicGoConvOpts = conv.Options{ EnableHttpMapping: true, EnableValueMapping: true, WriteRequireField: true, WriteDefaultField: true, OmitHttpMappingErrors: true, NoBase64Binary: true, UseKitexHttpEncoding: true, WriteHttpValueFallback: true, ReadHttpValueFallback: true, MergeBaseFunc: thrift.MergeBase, } DefaultJSONDynamicGoConvOpts = conv.Options{ WriteRequireField: true, WriteDefaultField: true, EnableValueMapping: true, String2Int64: true, MergeBaseFunc: thrift.MergeBase, } )
Functions ¶
func EnableSetFieldsForEmptyStruct ¶ added in v0.9.1
func EnableSetFieldsForEmptyStruct(g Generic, mode SetFieldsForEmptyStructMode) error
EnableSetFieldsForEmptyStruct enable/disable set all fields of a struct even if it is empty. This option is only applicable to map-generic response (reading) now.
mode == 0 means disable mode == 1 means only set required and default fields mode == 2 means set all fields
func ParseContent ¶ added in v0.3.3
func ParseContent(path, content string, includes map[string]string, isAbsIncludePath bool) (*parser.Thrift, error)
ParseContent parses the IDL from path and content using provided includes
func ServiceInfoWithGeneric ¶ added in v0.11.0
func ServiceInfoWithGeneric(g Generic) *serviceinfo.ServiceInfo
ServiceInfoWithGeneric create a generic ServiceInfo from Generic.
func SetBinaryWithBase64 ¶ added in v0.1.3
SetBinaryWithBase64 enable/disable Base64 codec for binary field.
func SetBinaryWithByteSlice ¶ added in v0.8.0
SetBinaryWithByteSlice enable/disable returning []byte for binary field.
func SetSeqID ¶ added in v0.1.0
SetSeqID is used to reset seqID for thrift payload. For client side, you don't need this function, Kitex will gen seqID and set it into transport protocol to ignore inconsistent seqID between thrift payload and transport protocol, reset the seqID to that generated by kitex for client side by default. But for server side(binary generic server), you need to return the same seqID with upstream, it is suggested to keep the upstream seqID(use GetSeqID) then use SetSeqID to reset the seqID of transBuff.
Types ¶
type BidiStreamingServer ¶ added in v0.15.0
type BidiStreamingServer interface {
// Recv receives a message from the client.
Recv(ctx context.Context) (req interface{}, err error)
// Send sends a message to the client.
Send(ctx context.Context, res interface{}) error
// SetHeader inherits from the underlying streaming.ServerStream.
SetHeader(hd streaming.Header) error
// SendHeader inherits from the underlying streaming.ServerStream.
SendHeader(hd streaming.Header) error
// SetTrailer inherits from the underlying streaming.ServerStream.
SetTrailer(hd streaming.Trailer) error
// Streaming returns the underlying streaming.ServerStream.
Streaming() streaming.ServerStream
}
BidiStreamingServer define server side bidi streaming APIs
type ClientStreamingServer ¶ added in v0.15.0
type ClientStreamingServer interface {
// Recv receives a message from the client.
Recv(ctx context.Context) (req interface{}, err error)
// SendAndClose sends a message to the client and closes the stream.
SendAndClose(ctx context.Context, res interface{}) error
// SetHeader inherits from the underlying streaming.ServerStream.
SetHeader(hd streaming.Header) error
// SendHeader inherits from the underlying streaming.ServerStream.
SendHeader(hd streaming.Header) error
// SetTrailer inherits from the underlying streaming.ServerStream.
SetTrailer(hd streaming.Trailer) error
// Streaming returns the underlying streaming.ServerStream.
Streaming() streaming.ServerStream
}
ClientStreamingServer define server side client streaming APIs
type Closer ¶ added in v0.1.0
type Closer interface {
// Close the unused resource.
Close() error
}
Closer is usually used to recycle resource.
type DescriptorProvider ¶
type DescriptorProvider interface {
Closer
// Provide return a channel for provide service descriptors
Provide() <-chan *descriptor.ServiceDescriptor
}
DescriptorProvider provide service descriptor
func NewThriftFileProvider ¶
func NewThriftFileProvider(path string, includeDirs ...string) (DescriptorProvider, error)
NewThriftFileProvider create a ThriftIDLProvider by given path and include dirs
func NewThriftFileProviderWithDynamicGo ¶ added in v0.7.0
func NewThriftFileProviderWithDynamicGo(path string, includeDirs ...string) (DescriptorProvider, error)
NewThriftFileProviderWithDynamicGo create a ThriftIDLProvider with dynamicgo by given path and include dirs
func NewThriftFileProviderWithDynamicgoWithOption ¶ added in v0.12.0
func NewThriftFileProviderWithDynamicgoWithOption(path string, opts []ThriftIDLProviderOption, includeDirs ...string) (DescriptorProvider, error)
func NewThriftFileProviderWithOption ¶ added in v0.12.0
func NewThriftFileProviderWithOption(path string, opts []ThriftIDLProviderOption, includeDirs ...string) (DescriptorProvider, error)
type Generic ¶
type Generic interface {
Closer
// PayloadCodecType return the type of codec
PayloadCodecType() serviceinfo.PayloadCodec
// GenericMethod return generic method func
GenericMethod() serviceinfo.GenericMethodFunc
// IDLServiceName returns idl service name
IDLServiceName() string
// GetExtra returns extra info by key
GetExtra(key string) interface{}
}
Generic ...
func BinaryPbGeneric ¶ added in v0.14.0
func BinaryThriftGeneric ¶
func BinaryThriftGeneric() Generic
BinaryThriftGeneric raw thrift binary Generic. Deprecated: use BinaryThriftGenericV2 instead.
func BinaryThriftGenericV2 ¶ added in v0.15.0
func HTTPPbThriftGeneric ¶ added in v0.4.0
func HTTPPbThriftGeneric(p DescriptorProvider, pbp PbDescriptorProvider) (Generic, error)
func HTTPThriftGeneric ¶
func HTTPThriftGeneric(p DescriptorProvider, opts ...Option) (Generic, error)
func JSONPbGeneric ¶ added in v0.9.0
func JSONPbGeneric(p PbDescriptorProviderDynamicGo, opts ...Option) (Generic, error)
func JSONThriftGeneric ¶
func JSONThriftGeneric(p DescriptorProvider, opts ...Option) (Generic, error)
func MapThriftGeneric ¶
func MapThriftGeneric(p DescriptorProvider) (Generic, error)
func MapThriftGenericForJSON ¶ added in v0.4.3
func MapThriftGenericForJSON(p DescriptorProvider) (Generic, error)
type GetMethodNameByRequestFunc ¶ added in v0.15.0
GetMethodNameByRequestFunc get method name by request for http generic.
type GetProviderOption ¶ added in v0.7.0
type GetProviderOption interface {
Option() ProviderOption
}
GetProviderOption provide options for descriptor provider
type HTTPRequest ¶
type HTTPRequest = descriptor.HTTPRequest
HTTPRequest alias of descriptor HTTPRequest
func FromHTTPPbRequest ¶ added in v0.4.0
func FromHTTPPbRequest(req *http.Request) (*HTTPRequest, error)
FromHTTPPbRequest parse HTTPRequest from http.Request
func FromHTTPRequest ¶
func FromHTTPRequest(req *http.Request) (*HTTPRequest, error)
FromHTTPRequest parse HTTPRequest from http.Request
type HTTPResponse ¶
type HTTPResponse = descriptor.HTTPResponse
HTTPResponse alias of descriptor HTTPResponse
type Method ¶
type Method struct {
Oneway bool
StreamingMode serviceinfo.StreamingMode
}
Method information of oneway and streaming mode
type Option ¶ added in v0.7.0
type Option struct {
F func(opt *Options)
}
func UseRawBodyForHTTPResp ¶ added in v0.7.0
UseRawBodyForHTTPResp sets whether to set body of response for http generic call into HTTPResponse.RawBody or not. if this is disabled, the body will be stored only into HTTPResponse.Body
func WithCustomDynamicGoConvOpts ¶ added in v0.7.0
WithCustomDynamicGoConvOpts sets custom conv.Options
type PbContentProvider ¶ added in v0.4.0
type PbContentProvider struct {
// contains filtered or unexported fields
}
func (*PbContentProvider) Close ¶ added in v0.4.0
func (p *PbContentProvider) Close() error
func (*PbContentProvider) Provide ¶ added in v0.4.0
func (p *PbContentProvider) Provide() <-chan proto.ServiceDescriptor
type PbDescriptorProvider ¶ added in v0.4.0
type PbDescriptorProvider interface {
Closer
// Provide return a channel for provide service descriptors
Provide() <-chan proto.ServiceDescriptor
}
PbDescriptorProvider provide service descriptor
func NewPbContentProvider ¶ added in v0.4.0
func NewPbContentProvider(main string, includes map[string]string) (PbDescriptorProvider, error)
type PbDescriptorProviderDynamicGo ¶ added in v0.9.0
type PbDescriptorProviderDynamicGo interface {
Closer
// Provide return a channel for provide service descriptors
Provide() <-chan *dproto.ServiceDescriptor
}
PbDescriptorProvider provide service descriptor
func NewPbContentProviderWithDynamicGo ¶ added in v0.10.0
func NewPbContentProviderWithDynamicGo(ctx context.Context, options dproto.Options, mainPath, mainContent string, includes map[string]string) (PbDescriptorProviderDynamicGo, error)
NewPbContentProviderWithDynamicGo creates PbFileProviderWithDynamicGo from memory. NOTICE: mainPath is used to store mainContent in includes, thus it MUST NOT conflict with original includes
func NewPbFileProviderWithDynamicGo ¶ added in v0.9.0
func NewPbFileProviderWithDynamicGo(main string, ctx context.Context, options dproto.Options, importDirs ...string) (PbDescriptorProviderDynamicGo, error)
NewPbFileProviderWithDynamicGo ..
type PbFileProviderWithDynamicGo ¶ added in v0.9.0
type PbFileProviderWithDynamicGo struct {
// contains filtered or unexported fields
}
func (*PbFileProviderWithDynamicGo) Close ¶ added in v0.9.0
func (p *PbFileProviderWithDynamicGo) Close() error
func (*PbFileProviderWithDynamicGo) Provide ¶ added in v0.9.0
func (p *PbFileProviderWithDynamicGo) Provide() <-chan *dproto.ServiceDescriptor
func (*PbFileProviderWithDynamicGo) UpdateIDL ¶ added in v0.10.0
func (p *PbFileProviderWithDynamicGo) UpdateIDL(ctx context.Context, options dproto.Options, mainPath, mainContent string, includes map[string]string) error
UpdateIDL updates idl NOTE: Since an IDL update is asynchronous, it may not be applied immediately, potentially causing a temporary data inconsistency.
type ProviderOption ¶ added in v0.7.0
type ServerStreamingServer ¶ added in v0.15.0
type ServerStreamingServer interface {
// Send sends a message to the client.
Send(ctx context.Context, res interface{}) error
// SetHeader inherits from the underlying streaming.ServerStream.
SetHeader(hd streaming.Header) error
// SendHeader inherits from the underlying streaming.ServerStream.
SendHeader(hd streaming.Header) error
// SetTrailer inherits from the underlying streaming.ServerStream.
SetTrailer(hd streaming.Trailer) error
// Streaming returns the underlying streaming.ServerStream.
Streaming() streaming.ServerStream
}
ServerStreamingServer define server side server streaming APIs
type Service ¶
type Service interface {
// GenericCall handle the generic call
GenericCall(ctx context.Context, method string, request interface{}) (response interface{}, err error)
}
Service is the v1 generic service interface.
type ServiceV2 ¶ added in v0.15.0
type ServiceV2 struct {
// GenericCall handles pingpong/unary requests.
//
// NOTE: If the generic type is BinaryThriftGenericV2, GRPC unary requests won't be handled by this method.
// Instead, they will be handled by BidiStreaming.
GenericCall func(ctx context.Context, service, method string, request interface{}) (response interface{}, err error)
// ClientStreaming handles client streaming call.
//
// NOTE: If the generic type is BinaryThriftGenericV2, Client streaming requests won't be handled by this method.
// Instead, they will be handled by BidiStreaming.
ClientStreaming func(ctx context.Context, service, method string, stream ClientStreamingServer) (err error)
// ServerStreaming handles server streaming call.
//
// NOTE: If the generic type is BinaryThriftGenericV2, Server streaming requests won't be handled by this method.
// Instead, they will be handled by BidiStreaming.
ServerStreaming func(ctx context.Context, service, method string, request interface{}, stream ServerStreamingServer) (err error)
// BidiStreaming handles the bidi streaming call.
//
// NOTE: If the generic type is BinaryThriftGenericV2, all streaming requests (including GRPC unary) will be handled
// by this method. Since we cannot determine the stream mode without IDL info, we can only treat the requests
// as bidi streaming by default.
BidiStreaming func(ctx context.Context, service, method string, stream BidiStreamingServer) (err error)
}
ServiceV2 is the new generic service interface, provides methods to handle streaming requests and it also supports multi services. All methods are optional.
type SetFieldsForEmptyStructMode ¶ added in v0.9.1
type SetFieldsForEmptyStructMode uint8
SetFieldsForEmptyStructMode is a enum for EnableSetFieldsForEmptyStruct()
const ( // NotSetFields means disable NotSetFields SetFieldsForEmptyStructMode = iota // SetNonOptiontionalFields means only set required and default fields SetNonOptiontionalFields // SetAllFields means set all fields SetAllFields )
type ThriftContentProvider ¶
type ThriftContentProvider struct {
// contains filtered or unexported fields
}
ThriftContentProvider provide descriptor from contents
func NewThriftContentProvider
deprecated
func NewThriftContentProvider(mainIDLContent string, includes map[string]string, opts ...ThriftIDLProviderOption) (*ThriftContentProvider, error)
Deprecated: Use NewThriftContentWithAbsIncludePathProvider instead.
NewThriftContentProvider creates a DescriptorProvider supporting only relative path search while NewThriftContentWithAbsIncludePathProvider supports both relative and absolute path searches Note: the first argument is the file content of the main IDL
func NewThriftContentProviderWithDynamicGo
deprecated
added in
v0.7.0
func NewThriftContentProviderWithDynamicGo(mainIDLContent string, includes map[string]string, opts ...ThriftIDLProviderOption) (*ThriftContentProvider, error)
Deprecated: Use NewThriftContentWithAbsIncludePathProviderWithDynamicGo instead.
NewThriftContentProviderWithDynamicGo creates a DescriptorProvider supporting only relative path search while NewThriftContentWithAbsIncludePathProviderWithDynamicGo supports both relative and absolute path searches Note: the first argument is the file content of the main IDL
func (*ThriftContentProvider) Close ¶ added in v0.1.0
func (p *ThriftContentProvider) Close() error
Close the sending chan.
func (*ThriftContentProvider) Option ¶ added in v0.7.0
func (p *ThriftContentProvider) Option() ProviderOption
Option ...
func (*ThriftContentProvider) Provide ¶
func (p *ThriftContentProvider) Provide() <-chan *descriptor.ServiceDescriptor
Provide ...
type ThriftContentWithAbsIncludePathProvider ¶
type ThriftContentWithAbsIncludePathProvider struct {
// contains filtered or unexported fields
}
ThriftContentWithAbsIncludePathProvider ...
func NewThriftContentWithAbsIncludePathProvider ¶
func NewThriftContentWithAbsIncludePathProvider(mainIDLPath string, includes map[string]string, opts ...ThriftIDLProviderOption) (*ThriftContentWithAbsIncludePathProvider, error)
NewThriftContentWithAbsIncludePathProvider creates a DescriptorProvider supporting both relative and absolute path searches NOTE: the first argument is the path to the main IDL file rather than its file content.
func NewThriftContentWithAbsIncludePathProviderWithDynamicGo ¶ added in v0.7.0
func NewThriftContentWithAbsIncludePathProviderWithDynamicGo(mainIDLPath string, includes map[string]string, opts ...ThriftIDLProviderOption) (*ThriftContentWithAbsIncludePathProvider, error)
NewThriftContentWithAbsIncludePathProviderWithDynamicGo creates a DescriptorProvider supporting both relative and absolute path searches NOTE: the first argument is the path to the main IDL file rather than its file content.
func (*ThriftContentWithAbsIncludePathProvider) Close ¶ added in v0.1.0
func (p *ThriftContentWithAbsIncludePathProvider) Close() error
Close the sending chan.
func (*ThriftContentWithAbsIncludePathProvider) Option ¶ added in v0.7.0
func (p *ThriftContentWithAbsIncludePathProvider) Option() ProviderOption
Option ...
func (*ThriftContentWithAbsIncludePathProvider) Provide ¶
func (p *ThriftContentWithAbsIncludePathProvider) Provide() <-chan *descriptor.ServiceDescriptor
Provide ...
func (*ThriftContentWithAbsIncludePathProvider) UpdateIDL ¶
func (p *ThriftContentWithAbsIncludePathProvider) UpdateIDL(mainIDLPath string, includes map[string]string) error
UpdateIDL updates idl NOTE: Since an IDL update is asynchronous, it may not be applied immediately, potentially causing a temporary data inconsistency.
type ThriftIDLProviderOption ¶ added in v0.12.0
type ThriftIDLProviderOption struct {
F func(opt *thriftIDLProviderOptions)
}
func WithDynamicGoOptions ¶ added in v0.15.3
func WithDynamicGoOptions(opts *dthrift.Options) ThriftIDLProviderOption
WithDynamicGoOptions passes the dynamicgo parsing options.
func WithGoTagDisabled ¶ added in v0.12.0
func WithGoTagDisabled(disable bool) ThriftIDLProviderOption
func WithIDLServiceName ¶ added in v0.12.2
func WithIDLServiceName(serviceName string) ThriftIDLProviderOption
WithIDLServiceName specifies the target IDL service to be parsed. NOTE: when using this option, the specified service is prioritized, and parse mode will be ignored.
func WithParseMode ¶ added in v0.12.0
func WithParseMode(parseMode thrift.ParseMode) ThriftIDLProviderOption
WithParseMode sets the parse mode. NOTE: when using WithIDLServiceName at the same time, parse mode will be ignored.
Source Files
¶
- binarypb_codec.go
- binarythrift_codec.go
- binarythrift_codec_v2.go
- closer.go
- descriptor_provider.go
- generic.go
- generic_service.go
- httppbthrift_codec.go
- httpthrift_codec.go
- jsonpb_codec.go
- jsonthrift_codec.go
- mapthrift_codec.go
- option.go
- pb_descriptor_provider.go
- pbidl_provider.go
- streaming.go
- thriftidl_provider.go
- thriftidl_provider_option.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package test ...
|
Package test ... |
|
Package descriptor the idl descriptor for describe the idls with golang
|
Package descriptor the idl descriptor for describe the idls with golang |
|
Package test ...
|
Package test ... |
|
Package test ...
|
Package test ... |
|
Package test ...
|
Package test ... |
|
Package test ...
|
Package test ... |
|
Package thrift provides thrift idl parser and codec for generic call
|
Package thrift provides thrift idl parser and codec for generic call |