Import path:
gitlab.soludian.com/soludian/fountain/libs/fnet/fgrpc
fgrpc
import "gitlab.soludian.com/soludian/fountain/libs/fnet/fgrpc"Index
- Constants
- Variables
- func BuildBufConnDialer(listener net.Listener) func(context.Context, string) (net.Conn, error)
- func RPCErrorFromMD(md metautils.MD) (rpcErr *froto.RpcError)
- func RPCErrorToMD(md *froto.RpcError) (metadata.MD, error)
- func WithAddr(addr string) lib_3rd.Option[config]
- func WithCounter(counter metrics.Counter) lib_3rd.Option[config]
- func WithDeployment(deployment string) lib_3rd.Option[config]
- func WithEnableAccessInterceptor(enable bool) lib_3rd.Option[config]
- func WithEnableAccessInterceptorReq(enable bool) lib_3rd.Option[config]
- func WithEnableAccessInterceptorRes(enable bool) lib_3rd.Option[config]
- func WithEnableLocalMainIP(enable bool) lib_3rd.Option[config]
- func WithEnableMetricInterceptor(enable bool) lib_3rd.Option[config]
- func WithEnableOfficialGRPCLog(enable bool) lib_3rd.Option[config]
- func WithEnableSkipHealthLog(enable bool) lib_3rd.Option[config]
- func WithEnableTraceInterceptor(enable bool) lib_3rd.Option[config]
- func WithHistogram(histogram metrics.Histogram) lib_3rd.Option[config]
- func WithName(name string) lib_3rd.Option[config]
- func WithNetwork(network string) lib_3rd.Option[config]
- func WithServerOptions(serverOptions ...grpc.ServerOption) lib_3rd.Option[config]
- func WithSlowLogThreshold(threshold time.Duration) lib_3rd.Option[config]
- func WithStreamInterceptors(streamInterceptors ...grpc.StreamServerInterceptor) lib_3rd.Option[config]
- func WithUnaryInterceptors(unaryInterceptors ...grpc.UnaryServerInterceptor) lib_3rd.Option[config]
- type DecodeRequestFunc
- type DecodeResponseFunc
- type EncodeRequestFunc
- type EncodeResponseFunc
- type Server
- func (s *Server) Destroy() error
- func (s *Server) GetAddress() string
- func (s *Server) GetConfig() *config
- func (s *Server) GetListener() net.Listener
- func (s *Server) GetName() string
- func (s *Server) GetPackageName() string
- func (s *Server) GracefulStop(ctx context.Context) error
- func (s *Server) Serving()
Constants
const KPackageName = "fgrpc"Variables
ConvertMDToRPCMetadataWithReflection chuyển đổi metadata.MD thành froto.RPCMetadata bằng cách sử dụng reflection để ánh xạ các trường dữ liệu.
Tham số:
- md: metadata.MD chứa các giá trị metadata cần chuyển đổi.
Trả về:
- *froto.RPCMetadata: Đối tượng RPCMetadata đã được ánh xạ từ metadata.MD.
Hàm này sử dụng reflection để duyệt qua các trường của struct RPCMetadata và ánh xạ các giá trị từ metadata.MD vào các trường tương ứng. Nếu trường có tag `json`, tên trường sẽ được lấy từ tag này. Nếu không, tên trường sẽ được lấy từ tên của trường trong struct. Hàm cũng xử lý các kiểu dữ liệu khác nhau như string, int, uint, float, và bool. Nếu metadata chứa trường "extend" hoặc "Extend", giá trị của trường này sẽ được chuyển đổi thành anypb.Any và gán vào trường Extend của RPCMetadata.
var ConvertMDToRPCMetadataWithReflection = froto.ConvertMDToRPCMetadataWithReflectionvar GetFountainInstance = Lib.GetFountainInstancevar GetFountainManager = Lib.GetFountainManagervar GetKeyFromNiceMetadata = froto.GetKeyFromNiceMetadataSử dụng khi config instance ở dạng key:value; Nếu config instance ở dạng key:array thì sử dụng hàm InstallFountainInstances Nếu config ở dạng key:array thì sẽ chỉ install config phần tử đầu tiên mà thôi
Install with config format <key>:<value>; eg: fgrpc:<value>
Usage:
config.yaml:
fgrpc:
- name: default_name
...
code.go
fgrpc.InstallFountainInstance()
fgrpc.WithConfigKey("fgrpc").InstallFountainInstance()var InstallFountainInstance = Lib.InstallFountainInstanceSử dụng khi config instance ở dạng key:array<value>; Sẽ luôn cố gắng khởi tạo kể cả khi config ở dạng key:value
Install with config format <key>:array<value>; eg: fgrpc:array<value>
Usage:
config.yaml:
fgrpc:
- name: default_name
...
code.go
fgrpc.InstallFountainInstances()
fgrpc.WithConfigKey("fgrpc").InstallFountainInstances()var InstallFountainInstances = Lib.InstallFountainInstancesvar KDefaultServerName = env.GetFullAppService(KPackageName)Truy cập thẳng tới bộ quản lý thư viện
var Lib = lib_3rd.NewLib(newServer, lib_3rd.WithDefaultConfigFunc[config, Server](DefaultConfig))var MetaDataKey = froto.MetaDataKeyvar RPCMetadataFromIncoming = froto.RPCMetadataFromIncomingRPCMetadataToIncomingForInternal chuyển đổi RPCMetadata thành Incoming Context cho internal server. Hàm này nhận vào một context và một con trỏ đến RPCMetadata, sau đó mã hóa RPCMetadata thành một chuỗi byte sử dụng proto.Marshal. Nếu quá trình mã hóa gặp lỗi, hàm sẽ ghi log lỗi và trả về nil. Nếu thành công, hàm sẽ tạo một Incoming Context mới với metadata chứa chuỗi byte đã mã hóa dưới dạng base64 và trả về context này.
ctx: context ban đầu. md: con trỏ đến RPCMetadata cần chuyển đổi.
Trả về: context mới chứa metadata đã mã hóa hoặc ctx gốc nếu có lỗi xảy ra.
var RPCMetadataToIncomingForInternal = froto.RPCMetadataToIncomingForInternalvar RPCMetadataToOutgoing = froto.RPCMetadataToOutgoingvar WithConfigKey = Lib.WithConfigKeyfunc BuildBufConnDialer
func BuildBufConnDialer(listener net.Listener) func(context.Context, string) (net.Conn, error)Convert net.Listener to *bufconn.Listener
func RPCErrorFromMD
func RPCErrorFromMD(md metautils.MD) (rpcErr *froto.RpcError)RPCErrorFromMD func Server To Client
func RPCErrorToMD
func RPCErrorToMD(md *froto.RpcError) (metadata.MD, error)func WithAddr
func WithAddr(addr string) lib_3rd.Option[config]func WithCounter
func WithCounter(counter metrics.Counter) lib_3rd.Option[config]func WithDeployment
func WithDeployment(deployment string) lib_3rd.Option[config]func WithEnableAccessInterceptor
func WithEnableAccessInterceptor(enable bool) lib_3rd.Option[config]func WithEnableAccessInterceptorReq
func WithEnableAccessInterceptorReq(enable bool) lib_3rd.Option[config]func WithEnableAccessInterceptorRes
func WithEnableAccessInterceptorRes(enable bool) lib_3rd.Option[config]func WithEnableLocalMainIP
func WithEnableLocalMainIP(enable bool) lib_3rd.Option[config]func WithEnableMetricInterceptor
func WithEnableMetricInterceptor(enable bool) lib_3rd.Option[config]func WithEnableOfficialGRPCLog
func WithEnableOfficialGRPCLog(enable bool) lib_3rd.Option[config]func WithEnableSkipHealthLog
func WithEnableSkipHealthLog(enable bool) lib_3rd.Option[config]func WithEnableTraceInterceptor
func WithEnableTraceInterceptor(enable bool) lib_3rd.Option[config]func WithHistogram
func WithHistogram(histogram metrics.Histogram) lib_3rd.Option[config]func WithName
func WithName(name string) lib_3rd.Option[config]func WithNetwork
func WithNetwork(network string) lib_3rd.Option[config]func WithServerOptions
func WithServerOptions(serverOptions ...grpc.ServerOption) lib_3rd.Option[config]func WithSlowLogThreshold
func WithSlowLogThreshold(threshold time.Duration) lib_3rd.Option[config]func WithStreamInterceptors
func WithStreamInterceptors(streamInterceptors ...grpc.StreamServerInterceptor) lib_3rd.Option[config]func WithUnaryInterceptors
func WithUnaryInterceptors(unaryInterceptors ...grpc.UnaryServerInterceptor) lib_3rd.Option[config]type DecodeRequestFunc
DecodeRequestFunc extracts a user-domain request object from a gRPC request. It's designed to be used in gRPC servers, for server-side endpoints. One straightforward DecodeRequestFunc could be something that decodes from the gRPC request message to the concrete request type.
type DecodeRequestFunc func(context.Context, any) (request any, err error)type DecodeResponseFunc
DecodeResponseFunc extracts a user-domain response object from a gRPC response object. It's designed to be used in gRPC clients, for client-side endpoints. One straightforward DecodeResponseFunc could be something that decodes from the gRPC response message to the concrete response type.
type DecodeResponseFunc func(context.Context, any) (response any, err error)type EncodeRequestFunc
EncodeRequestFunc encodes the passed request object into the gRPC request object. It's designed to be used in gRPC clients, for client-side endpoints. One straightforward EncodeRequestFunc could something that encodes the object directly to the gRPC request message.
type EncodeRequestFunc func(context.Context, any) (request any, err error)type EncodeResponseFunc
EncodeResponseFunc encodes the passed response object to the gRPC response message. It's designed to be used in gRPC servers, for server-side endpoints. One straightforward EncodeResponseFunc could be something that encodes the object directly to the gRPC response message.
type EncodeResponseFunc func(context.Context, any) (response any, err error)type Server
type Server struct {
*runnable.ServerInstance
*grpc.Server
// contains filtered or unexported fields
}func (*Server) Destroy
func (s *Server) Destroy() errorStop implements Runnable interface it will terminate echo server immediately
func (*Server) GetAddress
func (s *Server) GetAddress() stringAddress service address
func (*Server) GetConfig
func (s *Server) GetConfig() *configfunc (*Server) GetListener
func (s *Server) GetListener() net.ListenerListener listener information
func (*Server) GetName
func (s *Server) GetName() stringName configuration name
func (*Server) GetPackageName
func (s *Server) GetPackageName() stringPackageName package name
func (*Server) GracefulStop
func (s *Server) GracefulStop(ctx context.Context) errorGracefulStop implements Runnable interface it will stop echo server gracefully
func (*Server) Serving
func (s *Server) Serving()Serving func; Need run in a goroutine
Generated by gomarkdoc