Skip to content

Import path: gitlab.soludian.com/soludian/fountain/libs/fnet/fgrpc

fgrpc

go
import "gitlab.soludian.com/soludian/fountain/libs/fnet/fgrpc"

Index

Constants

PackageName package name

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

go
var ConvertMDToRPCMetadataWithReflection = froto.ConvertMDToRPCMetadataWithReflection

go
var GetFountainInstance = Lib.GetFountainInstance

go
var GetFountainManager = Lib.GetFountainManager

go
var GetKeyFromNiceMetadata = froto.GetKeyFromNiceMetadata

Sử 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()
go
var InstallFountainInstance = Lib.InstallFountainInstance

Sử 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()
go
var InstallFountainInstances = Lib.InstallFountainInstances

go
var KDefaultServerName = env.GetFullAppService(KPackageName)

Truy cập thẳng tới bộ quản lý thư viện

go
var Lib = lib_3rd.NewLib(newServer, lib_3rd.WithDefaultConfigFunc[config, Server](DefaultConfig))

go
var MetaDataKey = froto.MetaDataKey

Using 'fgrpc_metadata' key

go
var RPCMetadataFromIncoming = froto.RPCMetadataFromIncoming

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

go
var RPCMetadataToIncomingForInternal = froto.RPCMetadataToIncomingForInternal

Using 'fgrpc_metadata' key

go
var RPCMetadataToOutgoing = froto.RPCMetadataToOutgoing

go
var WithConfigKey = Lib.WithConfigKey

func BuildBufConnDialer

go
func BuildBufConnDialer(listener net.Listener) func(context.Context, string) (net.Conn, error)

Convert net.Listener to *bufconn.Listener

func RPCErrorFromMD

go
func RPCErrorFromMD(md metautils.MD) (rpcErr *froto.RpcError)

RPCErrorFromMD func Server To Client

func RPCErrorToMD

go
func RPCErrorToMD(md *froto.RpcError) (metadata.MD, error)

func WithAddr

go
func WithAddr(addr string) lib_3rd.Option[config]

func WithCounter

go
func WithCounter(counter metrics.Counter) lib_3rd.Option[config]

func WithDeployment

go
func WithDeployment(deployment string) lib_3rd.Option[config]

func WithEnableAccessInterceptor

go
func WithEnableAccessInterceptor(enable bool) lib_3rd.Option[config]

func WithEnableAccessInterceptorReq

go
func WithEnableAccessInterceptorReq(enable bool) lib_3rd.Option[config]

func WithEnableAccessInterceptorRes

go
func WithEnableAccessInterceptorRes(enable bool) lib_3rd.Option[config]

func WithEnableLocalMainIP

go
func WithEnableLocalMainIP(enable bool) lib_3rd.Option[config]

func WithEnableMetricInterceptor

go
func WithEnableMetricInterceptor(enable bool) lib_3rd.Option[config]

func WithEnableOfficialGRPCLog

go
func WithEnableOfficialGRPCLog(enable bool) lib_3rd.Option[config]

func WithEnableSkipHealthLog

go
func WithEnableSkipHealthLog(enable bool) lib_3rd.Option[config]

func WithEnableTraceInterceptor

go
func WithEnableTraceInterceptor(enable bool) lib_3rd.Option[config]

func WithHistogram

go
func WithHistogram(histogram metrics.Histogram) lib_3rd.Option[config]

func WithName

go
func WithName(name string) lib_3rd.Option[config]

func WithNetwork

go
func WithNetwork(network string) lib_3rd.Option[config]

func WithServerOptions

go
func WithServerOptions(serverOptions ...grpc.ServerOption) lib_3rd.Option[config]

func WithSlowLogThreshold

go
func WithSlowLogThreshold(threshold time.Duration) lib_3rd.Option[config]

func WithStreamInterceptors

go
func WithStreamInterceptors(streamInterceptors ...grpc.StreamServerInterceptor) lib_3rd.Option[config]

func WithUnaryInterceptors

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

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

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

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

go
type EncodeResponseFunc func(context.Context, any) (response any, err error)

type Server

go
type Server struct {
    *runnable.ServerInstance
    *grpc.Server
    // contains filtered or unexported fields
}

func (*Server) Destroy

go
func (s *Server) Destroy() error

Stop implements Runnable interface it will terminate echo server immediately

func (*Server) GetAddress

go
func (s *Server) GetAddress() string

Address service address

func (*Server) GetConfig

go
func (s *Server) GetConfig() *config

func (*Server) GetListener

go
func (s *Server) GetListener() net.Listener

Listener listener information

func (*Server) GetName

go
func (s *Server) GetName() string

Name configuration name

func (*Server) GetPackageName

go
func (s *Server) GetPackageName() string

PackageName package name

func (*Server) GracefulStop

go
func (s *Server) GracefulStop(ctx context.Context) error

GracefulStop implements Runnable interface it will stop echo server gracefully

func (*Server) Serving

go
func (s *Server) Serving()

Serving func; Need run in a goroutine

Generated by gomarkdoc