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 ¶
- type Client
- type MetricsCollector
- type Option
- func WithGenerateCodeTimeout(d time.Duration) Option
- func WithHealthCheck(interval time.Duration) Option
- func WithInsecure() Option
- func WithKeepaliveParams(params keepalive.ClientParameters) Option
- func WithListPluginsTimeout(d time.Duration) Option
- func WithLoggingInterceptor(logger *slog.Logger) Option
- func WithMaxRetries(n int) Option
- func WithMetricsInterceptor(collector MetricsCollector) Option
- func WithRetryBaseDelay(d time.Duration) Option
- func WithTransportCredentials(creds credentials.TransportCredentials) Option
- func WithUnaryInterceptor(i grpc.UnaryClientInterceptor) Option
- type PluginFilter
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 (*Client) Close ¶
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 ¶
WithGenerateCodeTimeout sets the default timeout for GenerateCode calls.
func WithHealthCheck ¶
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 ¶
WithListPluginsTimeout sets the default timeout for ListPlugins calls.
func WithLoggingInterceptor ¶
WithLoggingInterceptor adds a built-in logging interceptor that records the RPC method, call duration, and response status code.
func WithMaxRetries ¶
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 ¶
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.