sdk

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package sdk provides a client for the EasyP API Service.

The SDK simplifies interaction with the EasyP API Service, allowing you to list available plugins and execute code generation requests remotely.

Example usage:

c, err := sdk.NewClient("localhost:8080", sdk.WithInsecure())
if err != nil {
    log.Fatal(err)
}
defer c.Close()

plugins, err := c.ListPlugins(context.Background())
if err != nil {
    log.Fatal(err)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a client for the EasyP API Service.

func NewClient

func NewClient(addr string, opts ...Option) (*Client, error)

NewClient creates a new Client connected to the specified address.

func (*Client) Close

func (c *Client) Close() error

Close closes the underlying gRPC connection. If a health monitor is running, it is stopped first.

func (*Client) GenerateCode

func (c *Client) GenerateCode(ctx context.Context, pluginName string, req *pluginpb.CodeGeneratorRequest) (*pluginpb.CodeGeneratorResponse, error)

GenerateCode executes a plugin to generate code.

func (*Client) ListPlugins

func (c *Client) ListPlugins(ctx context.Context, filter ...PluginFilter) ([]*generator.PluginInfo, error)

ListPlugins retrieves a list of available plugins, optionally filtered.

type MetricsCollector

type MetricsCollector interface {
	RecordCall(method string, duration time.Duration, code codes.Code)
}

MetricsCollector is the interface for collecting SDK call metrics.

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option configures the client.

func WithGenerateCodeTimeout

func WithGenerateCodeTimeout(d time.Duration) Option

WithGenerateCodeTimeout sets the default timeout for GenerateCode calls.

func WithHealthCheck

func WithHealthCheck(interval time.Duration) Option

WithHealthCheck enables periodic connection health monitoring with the given interval.

func WithInsecure

func WithInsecure() Option

WithInsecure disables Transport Security (TLS). Use this option for local development or testing.

func WithKeepaliveParams

func WithKeepaliveParams(params keepalive.ClientParameters) Option

WithKeepaliveParams sets gRPC keepalive parameters for the connection.

func WithListPluginsTimeout

func WithListPluginsTimeout(d time.Duration) Option

WithListPluginsTimeout sets the default timeout for ListPlugins calls.

func WithLoggingInterceptor

func WithLoggingInterceptor(logger *slog.Logger) Option

WithLoggingInterceptor adds a built-in logging interceptor that records the RPC method, call duration, and response status code.

func WithMaxRetries

func WithMaxRetries(n int) Option

WithMaxRetries sets the maximum number of retry attempts for transient errors.

func WithMetricsInterceptor

func WithMetricsInterceptor(collector MetricsCollector) Option

WithMetricsInterceptor adds a built-in metrics interceptor that records call counts, durations, and response codes via the provided MetricsCollector.

func WithRetryBaseDelay

func WithRetryBaseDelay(d time.Duration) Option

WithRetryBaseDelay sets the base delay between retry attempts.

func WithTransportCredentials

func WithTransportCredentials(creds credentials.TransportCredentials) Option

WithTransportCredentials sets custom transport credentials.

func WithUnaryInterceptor

func WithUnaryInterceptor(i grpc.UnaryClientInterceptor) Option

WithUnaryInterceptor appends a gRPC unary client interceptor to the chain.

type PluginFilter

type PluginFilter struct {
	Group   string
	Name    string
	Version string
	Tags    []string
}

PluginFilter задаёт критерии фильтрации плагинов. Пустые поля игнорируются (не участвуют в фильтрации).

Jump to

Keyboard shortcuts

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