Documentation
¶
Index ¶
Constants ¶
View Source
const ( // PermitWithoutStreamFieldName разрешать keepalive без стримов PermitWithoutStreamFieldName = "client.grpc.permit_without_stream" // KeepaliveTimeFieldName интервал keepalive пингов KeepaliveTimeFieldName = "client.grpc.keepalive.time" // KeepaliveTimeoutFieldName таймаут keepalive KeepaliveTimeoutFieldName = "client.grpc.keepalive.timeout" // AddressFieldName адрес сервера AddressFieldName = "client.grpc.address" // PortFieldName порт сервера PortFieldName = "client.grpc.port" )
Variables ¶
View Source
var ( PermitWithoutStreamDefault = true KeepaliveTimeDefault = time.Second * 10 KeepaliveTimeoutDefault = time.Second * 20 AddressDefault = "127.0.0.1" PortDefault = uint16(9090) )
View Source
var Component = compogo.Component{ Init: compogo.StepFunc(func(container compogo.Container) error { return container.Provides( NewConfig, NewClient, func(client *Client) grpc.ClientConnInterface { return client }, ) }), BindFlags: compogo.BindFlags(func(flagSet flag.FlagSet, container compogo.Container) error { return container.Invoke(func(config *Config) { flagSet.StringVar(&config.Address, AddressFieldName, AddressDefault, "") flagSet.Uint16Var(&config.Port, PortFieldName, PortDefault, "") flagSet.BoolVar(&config.PermitWithoutStream, PermitWithoutStreamFieldName, PermitWithoutStreamDefault, "") flagSet.DurationVar(&config.KeepaliveTime, KeepaliveTimeFieldName, KeepaliveTimeDefault, "") flagSet.DurationVar(&config.KeepaliveTimeout, KeepaliveTimeoutFieldName, KeepaliveTimeoutDefault, "") }) }), Configuration: compogo.StepFunc(func(container compogo.Container) error { return container.Invoke(Configuration) }), Stop: compogo.StepFunc(func(container compogo.Container) error { return container.Invoke(func(client *Client) error { return client.Close() }) }), }
Component — компонент GRPC-клиента для Compogo. Регистрирует клиент в DI-контейнере.
Пример:
app.AddComponents(&grpc_client.Component)
var client *grpc_client.Client
container.Invoke(func(c *grpc_client.Client) { client = c })
// Использование как grpc.ClientConnInterface
response, err := client.Invoke(ctx, "/MyService/Get", &Request{}, &Response{})
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client представляет GRPC-клиент с поддержкой keepalive. Реализует интерфейс grpc.ClientConnInterface.
func NewClient ¶
NewClient создаёт новый GRPC-клиент. Настраивает keepalive параметры и insecure соединение.
func (*Client) Invoke ¶
func (client *Client) Invoke(ctx context.Context, method string, args interface{}, reply interface{}, opts ...grpc.CallOption) error
Invoke вызывает RPC метод. Реализует интерфейс grpc.ClientConnInterface.
func (*Client) NewStream ¶
func (client *Client) NewStream(ctx context.Context, desc *grpc.StreamDesc, method string, opts ...grpc.CallOption) (grpc.ClientStream, error)
NewStream создаёт новый стрим. Реализует интерфейс grpc.ClientConnInterface.
type Config ¶
type Config struct {
PermitWithoutStream bool
Port uint16
Address string
KeepaliveTime time.Duration
KeepaliveTimeout time.Duration
}
Config содержит конфигурацию GRPC-клиента.
func Configuration ¶
func Configuration(config *Config, configurator compogo.Configurator) *Config
Configuration загружает конфигурацию из Configurator.
Click to show internal directories.
Click to hide internal directories.