Documentation ¶
Overview ¶
Package generic ...
Index ¶
- Constants
- Variables
- func EnableSetFieldsForEmptyStruct(g Generic, mode SetFieldsForEmptyStructMode) error
- func GetMethodInfo(messageReaderWriter interface{}, serviceName string) (methods map[string]serviceinfo.MethodInfo, svcName string)
- func GetSeqID(transBuff []byte) (int32, error)
- func ParseContent(path, content string, includes map[string]string, isAbsIncludePath bool) (*parser.Thrift, error)
- func ServiceInfo(pcType serviceinfo.PayloadCodec) *serviceinfo.ServiceInfodeprecated
- 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
- func (g *Args) GetFirstArgument() interface{}
- func (g *Args) GetOrSetBase() interface{}
- func (g *Args) Read(ctx context.Context, method string, dataLen int, in bufiox.Reader) error
- func (g *Args) ReadPb(ctx context.Context, method string, in []byte) error
- func (g *Args) SetCodec(inner interface{})
- func (g *Args) Write(ctx context.Context, method string, out bufiox.Writer) error
- func (g *Args) WritePb(ctx context.Context, method string) (interface{}, error)
- type Closer
- type DescriptorProvider
- type Generic
- func BinaryThriftGeneric() 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 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
- func (r *Result) GetResult() interface{}
- func (r *Result) GetSuccess() interface{}
- func (r *Result) IsSetSuccess() bool
- func (r *Result) Read(ctx context.Context, method string, dataLen int, in bufiox.Reader) error
- func (r *Result) ReadPb(ctx context.Context, method string, in []byte) error
- func (r *Result) SetCodec(inner interface{})
- func (r *Result) SetSuccess(x interface{})
- func (r *Result) Write(ctx context.Context, method string, out bufiox.Writer) error
- func (r *Result) WritePb(ctx context.Context, method string) (interface{}, error)
- type Service
- 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 WithCodec
Constants ¶
const DeprecatedGenericServiceInfoAPIKey = "deprecated_generic_service_info_api"
TODO(marina.sakai): remove in v0.12.0
Variables ¶
var ( DefaultHTTPDynamicGoConvOpts = conv.Options{ EnableHttpMapping: true, EnableValueMapping: true, WriteRequireField: true, WriteDefaultField: true, OmitHttpMappingErrors: true, NoBase64Binary: true, UseKitexHttpEncoding: true, } DefaultJSONDynamicGoConvOpts = conv.Options{ WriteRequireField: true, WriteDefaultField: true, EnableValueMapping: true, String2Int64: true, } )
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 GetMethodInfo ¶ added in v0.11.0
func GetMethodInfo(messageReaderWriter interface{}, serviceName string) (methods map[string]serviceinfo.MethodInfo, svcName string)
GetMethodInfo is only used in kitex, please DON'T USE IT. This method may be removed in the future
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 ServiceInfo
deprecated
func ServiceInfo(pcType serviceinfo.PayloadCodec) *serviceinfo.ServiceInfo
Deprecated: Replaced by ServiceInfoWithGeneric, this method will be removed in v0.12.0 ServiceInfo create a generic ServiceInfo TODO(marina.sakai): remove in v0.12.0
func ServiceInfoWithGeneric ¶ added in v0.11.0
func ServiceInfoWithGeneric(g Generic) *serviceinfo.ServiceInfo
ServiceInfoWithGeneric create a generic ServiceInfo
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 Args ¶
type Args struct { Request interface{} Method string // contains filtered or unexported fields }
Args generic request
func (*Args) GetFirstArgument ¶ added in v0.5.0
func (g *Args) GetFirstArgument() interface{}
GetFirstArgument implements util.KitexArgs.
func (*Args) GetOrSetBase ¶
func (g *Args) GetOrSetBase() interface{}
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
type Generic ¶
type Generic interface { Closer // PayloadCodec return codec implement // this is used for generic which does not need IDL PayloadCodec() remote.PayloadCodec // PayloadCodecType return the type of codec PayloadCodecType() serviceinfo.PayloadCodec // RawThriftBinaryGeneric must be framed Framed() bool // GetMethod is to get method name if needed GetMethod(req interface{}, method string) (*Method, error) // IDLServiceName returns idl service name IDLServiceName() string // MessageReaderWriter returns reader and writer // this is used for generic which needs IDL MessageReaderWriter() interface{} }
Generic ...
func BinaryThriftGeneric ¶
func BinaryThriftGeneric() Generic
BinaryThriftGeneric raw thrift binary Generic
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)
HTTPThriftGeneric http mapping Generic. Base64 codec for binary field is disabled by default. You can change this option with SetBinaryWithBase64. eg:
g, err := generic.HTTPThriftGeneric(p) SetBinaryWithBase64(g, true)
func JSONPbGeneric ¶ added in v0.9.0
func JSONPbGeneric(p PbDescriptorProviderDynamicGo, opts ...Option) (Generic, error)
JSONPbGeneric json mapping generic. Uses dynamicgo for json to protobufs conversion, so DynamicGo field is true by default.
func JSONThriftGeneric ¶
func JSONThriftGeneric(p DescriptorProvider, opts ...Option) (Generic, error)
JSONThriftGeneric json mapping generic. Base64 codec for binary field is enabled by default. You can change this option with SetBinaryWithBase64. eg:
g, err := generic.JSONThriftGeneric(p) SetBinaryWithBase64(g, false)
func MapThriftGeneric ¶
func MapThriftGeneric(p DescriptorProvider) (Generic, error)
MapThriftGeneric map mapping generic Base64 codec for binary field is disabled by default. You can change this option with SetBinaryWithBase64. eg:
g, err := generic.MapThriftGeneric(p) SetBinaryWithBase64(g, true)
String value is returned for binary field by default. You can change the return value to []byte for binary field with SetBinaryWithByteSlice. eg:
SetBinaryWithByteSlice(g, true)
func MapThriftGenericForJSON ¶ added in v0.4.3
func MapThriftGenericForJSON(p DescriptorProvider) (Generic, error)
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 { Name string Oneway bool StreamingMode serviceinfo.StreamingMode }
Method information
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)
PbFileProviderWithDynamicGo
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
type ProviderOption ¶ added in v0.7.0
type ProviderOption struct { // DynamicGoEnabled is if dynamicgo is enabled or not DynamicGoEnabled bool }
type Result ¶
type Result struct { Success interface{} // contains filtered or unexported fields }
Result generic response
func (*Result) GetSuccess ¶
func (r *Result) GetSuccess() interface{}
GetSuccess implements util.KitexResult.
func (*Result) SetSuccess ¶
func (r *Result) SetSuccess(x interface{})
SetSuccess implements util.KitexResult.
type Service ¶
type Service interface { // GenericCall handle the generic call GenericCall(ctx context.Context, method string, request interface{}) (response interface{}, err error) }
Service generic service interface
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 ¶
func NewThriftContentProvider(main string, includes map[string]string) (*ThriftContentProvider, error)
NewThriftContentProvider builder
func NewThriftContentProviderWithDynamicGo ¶ added in v0.7.0
func NewThriftContentProviderWithDynamicGo(main string, includes map[string]string) (*ThriftContentProvider, error)
NewThriftContentProviderWithDynamicGo builder
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) (*ThriftContentWithAbsIncludePathProvider, error)
NewThriftContentWithAbsIncludePathProvider create abs include path DescriptorProvider
func NewThriftContentWithAbsIncludePathProviderWithDynamicGo ¶ added in v0.7.0
func NewThriftContentWithAbsIncludePathProviderWithDynamicGo(mainIDLPath string, includes map[string]string) (*ThriftContentWithAbsIncludePathProvider, error)
NewThriftContentWithAbsIncludePathProviderWithDynamicGo create abs include path DescriptorProvider with dynamicgo
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 ...
Source Files ¶
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 |