generic

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package generic ...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSeqID

func GetSeqID(transBuff []byte) (int32, error)

GetSeqID from thrift buffered binary.

func ParseContent

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

func ServiceInfo(pcType serviceinfo.PayloadCodec) *serviceinfo.ServiceInfo

ServiceInfo create a generic ServiceInfo

func SetBinaryWithBase64

func SetBinaryWithBase64(g Generic, enable bool) error

SetBinaryWithBase64 enable/disable Base64 codec for binary field.

func SetSeqID

func SetSeqID(seqID int32, transBuff []byte) error

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

func (g *Args) GetFirstArgument() interface{}

GetFirstArgument implements util.KitexArgs.

func (*Args) GetOrSetBase

func (g *Args) GetOrSetBase() interface{}

func (*Args) Read

func (g *Args) Read(ctx context.Context, method string, in thrift.TProtocol) error

Read ...

func (*Args) SetCodec

func (g *Args) SetCodec(inner interface{})

SetCodec ...

func (*Args) Write

func (g *Args) Write(ctx context.Context, out thrift.TProtocol) error

Write ...

type Closer

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

type Generic

type Generic interface {
	Closer
	// PayloadCodec return codec implement
	PayloadCodec() remote.PayloadCodec
	// PayloadCodecType return the type of codec
	PayloadCodecType() serviceinfo.PayloadCodec
	// RawThriftBinaryGeneric must be framed
	Framed() bool
	// GetMethod to get method name if need
	GetMethod(req interface{}, method string) (*Method, error)
}

Generic ...

func BinaryThriftGeneric

func BinaryThriftGeneric() Generic

BinaryThriftGeneric raw thrift binary Generic

func HTTPPbThriftGeneric

func HTTPPbThriftGeneric(p DescriptorProvider, pbp PbDescriptorProvider) (Generic, error)

func HTTPThriftGeneric

func HTTPThriftGeneric(p DescriptorProvider) (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 JSONProtoGeneric

func JSONProtoGeneric(p PbDescriptorProvider) (Generic, error)

JSONProtoGeneric json mapping generic.

func JSONThriftGeneric

func JSONThriftGeneric(p DescriptorProvider) (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

func MapThriftGenericForJSON

func MapThriftGenericForJSON(p DescriptorProvider) (Generic, error)

type HTTPRequest

type HTTPRequest = descriptor.HTTPRequest

HTTPRequest alias of descriptor HTTPRequest

func FromHTTPPbRequest

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 JSONRequest

type JSONRequest = string

JSONRequest alias of string

type Method

type Method struct {
	Name   string
	Oneway bool
}

Method information

type PbContentProvider

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

func (*PbContentProvider) Close

func (p *PbContentProvider) Close() error

func (*PbContentProvider) Provide

func (p *PbContentProvider) Provide() <-chan proto.ServiceDescriptor

func (*PbContentProvider) UpdateIDL

func (p *PbContentProvider) UpdateIDL(main string, includes map[string]string) error

type PbDescriptorProvider

type PbDescriptorProvider interface {
	Closer
	// Provide return a channel for provide service descriptors
	Provide() <-chan proto.ServiceDescriptor
}

PbDescriptorProvider provide service descriptor

func NewPbContentProvider

func NewPbContentProvider(main string, includes map[string]string) (PbDescriptorProvider, error)

type Result

type Result struct {
	Success interface{}
	// contains filtered or unexported fields
}

Result generic response

func (*Result) GetResult

func (r *Result) GetResult() interface{}

GetResult ...

func (*Result) GetSuccess

func (r *Result) GetSuccess() interface{}

GetSuccess implements util.KitexResult.

func (*Result) IsSetSuccess

func (r *Result) IsSetSuccess() bool

IsSetSuccess ...

func (*Result) Read

func (r *Result) Read(ctx context.Context, method string, in thrift.TProtocol) error

Read ...

func (*Result) SetCodec

func (r *Result) SetCodec(inner interface{})

SetCodec ...

func (*Result) SetSuccess

func (r *Result) SetSuccess(x interface{})

SetSuccess implements util.KitexResult.

func (*Result) Write

func (r *Result) Write(ctx context.Context, out thrift.TProtocol) error

Write ...

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 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 (*ThriftContentProvider) Close

func (p *ThriftContentProvider) Close() error

Close the sending chan.

func (*ThriftContentProvider) Provide

func (p *ThriftContentProvider) Provide() <-chan *descriptor.ServiceDescriptor

Provide ...

func (*ThriftContentProvider) UpdateIDL

func (p *ThriftContentProvider) UpdateIDL(main string, includes map[string]string) error

UpdateIDL ...

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 (*ThriftContentWithAbsIncludePathProvider) Close

Close the sending chan.

func (*ThriftContentWithAbsIncludePathProvider) Provide

Provide ...

func (*ThriftContentWithAbsIncludePathProvider) UpdateIDL

func (p *ThriftContentWithAbsIncludePathProvider) UpdateIDL(mainIDLPath string, includes map[string]string) error

UpdateIDL update idl by given args

type WithCodec

type WithCodec interface {
	SetCodec(codec interface{})
}

WithCodec set codec instance for Args or Result

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 ...
idl
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

Jump to

Keyboard shortcuts

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