client

package
v0.4.0-beta Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package client implements the Translaas SDK HTTP client matching .NET TranslaasClient.

Package client implements the Translaas SDK HTTP client matching .NET TranslaasClient.

Index

Constants

View Source
const (
	// DefaultTimeout is applied when Options.Timeout is zero.
	DefaultTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client interface {
	GetEntry(ctx context.Context, group, entry, lang string, opts ...GetEntryOption) (string, error)

	GetGroup(ctx context.Context, project, group, lang string, opts ...GetGroupOption) (*models.TranslationGroup, error)
	GetProject(ctx context.Context, project, lang string, opts ...GetProjectOption) (*models.TranslationProject, error)
	GetProjectLocales(ctx context.Context, project string, opts ...GetProjectLocalesOption) (*models.ProjectLocales, error)
	GetOfflineCache(ctx context.Context, project string, opts ...GetOfflineCacheOption) (*models.OfflineCacheDownloadResult, error)

	ReportMissingKeys(ctx context.Context, keys []models.ReportMissingKeyItem) error
	ValidateAPIKey(ctx context.Context) (*models.ValidateAPIKeyResponse, error)
}

Client is the consumer-facing HTTP client boundary.

func New

func New(opts Options, optFns ...Option) (Client, error)

New constructs a Client with validated options.

func NewWithResolvedProject

func NewWithResolvedProject(ctx context.Context, opts Options, optFns ...Option) (Client, error)

NewWithResolvedProject constructs a Client, resolving DefaultProjectID from ValidateAPIKey when it is not configured and the API key is scoped to a single project.

type GetEntryCallOptions

type GetEntryCallOptions struct {
	Number         *float64
	Parameters     map[string]string
	RequestContext *models.RequestContext
}

GetEntryCallOptions holds parsed GetEntry call options for decorators.

func ParseGetEntryOptions

func ParseGetEntryOptions(opts ...GetEntryOption) GetEntryCallOptions

ParseGetEntryOptions parses GetEntry options for use by decorators.

type GetEntryOption

type GetEntryOption func(*getEntryConfig)

GetEntryOption configures a single GetEntry call.

func WithNumber

func WithNumber(n float64) GetEntryOption

WithNumber sets the plural/interpolation count (merged as query key N).

func WithParameters

func WithParameters(params map[string]string) GetEntryOption

WithParameters adds interpolation query parameters merged after the request DTO.

func WithRequestContext

func WithRequestContext(rc *models.RequestContext) GetEntryOption

WithRequestContext supplies per-request channel, version, project, and conditional headers.

type GetGroupOption

type GetGroupOption func(*getGroupConfig)

GetGroupOption configures a single GetGroup call.

func WithGroupFormat

func WithGroupFormat(format string) GetGroupOption

WithGroupFormat sets the response format query parameter (for example "flat-json").

func WithGroupRequestContext

func WithGroupRequestContext(rc *models.RequestContext) GetGroupOption

WithGroupRequestContext supplies per-request channel, version, includeContext, and conditional headers.

type GetOfflineCacheOption

type GetOfflineCacheOption func(*getOfflineCacheConfig)

GetOfflineCacheOption configures a single GetOfflineCache call.

func WithOfflineCacheRequestContext

func WithOfflineCacheRequestContext(rc *models.RequestContext) GetOfflineCacheOption

WithOfflineCacheRequestContext supplies per-request channel, version, includeContext, and conditional headers.

type GetProjectLocalesOption

type GetProjectLocalesOption func(*getProjectLocalesConfig)

GetProjectLocalesOption configures a single GetProjectLocales call.

func WithLocalesRequestContext

func WithLocalesRequestContext(rc *models.RequestContext) GetProjectLocalesOption

WithLocalesRequestContext supplies per-request channel, version, and conditional headers.

type GetProjectOption

type GetProjectOption func(*getProjectConfig)

GetProjectOption configures a single GetProject call.

func WithProjectFormat

func WithProjectFormat(format string) GetProjectOption

WithProjectFormat sets the response format query parameter (for example "flat-json").

func WithProjectRequestContext

func WithProjectRequestContext(rc *models.RequestContext) GetProjectOption

WithProjectRequestContext supplies per-request channel, version, includeContext, and conditional headers.

type Option

type Option func(*clientConfig)

Option configures client construction.

func WithCacheMode

func WithCacheMode(mode cache.Mode) Option

WithCacheMode overrides Options.CacheMode.

func WithCacheProvider

func WithCacheProvider(provider cache.Provider) Option

WithCacheProvider supplies a custom in-memory cache provider (primarily for tests).

func WithCacheTTL

func WithCacheTTL(ttl cache.TTL) Option

WithCacheTTL overrides Options.CacheTTL.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) Option

WithHTTPClient supplies a custom HTTP client (primarily for tests).

type Options

type Options struct {
	APIKey           string
	BaseURL          string
	Timeout          time.Duration
	DefaultProjectID string
	CacheMode        cache.Mode
	CacheTTL         cache.TTL
}

Options configures the Translaas HTTP client.

Jump to

Keyboard shortcuts

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