Files
tm_back/pkg/ai_summarizer/config.go
T
Mazyar 2e112fe08c
continuous-integration/drone/push Build is passing
Update MinIO bucket configuration and enhance dashboard service caching
- Changed the default MinIO bucket name from "opplens-documents" to "opplens" across multiple configuration files.
- Introduced caching for dashboard statistics in the service layer to improve performance and reduce redundant data fetching.
- Implemented a mutex for thread-safe access to cached statistics, ensuring data integrity during concurrent requests.

This update streamlines the configuration for the AI summarizer and optimizes the dashboard service, enhancing overall system efficiency.
2026-06-14 15:14:02 +03:30

82 lines
2.6 KiB
Go

package ai_summarizer
import (
"context"
"errors"
"fmt"
"time"
)
// Config holds the configuration for the AI Summarizer service.
// It contains settings for both the HTTP API and the MinIO storage integration.
type Config struct {
// HTTP API settings
APIBaseURL string // Base URL of the AI service, e.g. "http://ai-host:8000"
APITimeout time.Duration // Timeout for HTTP requests to the AI API
APIRetryCount int // Number of retry attempts for failed API requests
APIRetryDelay time.Duration // Delay between retry attempts
// OnSuccessfulTranslation is called after a successful POST /ai/translate request.
// source identifies the caller (daily_job or manual_trigger).
OnSuccessfulTranslation func(ctx context.Context, source string) error
// MinIO storage settings
MinioEndpoint string // MinIO endpoint, e.g. "ai-host:9000"
MinioAccessKey string // MinIO access key ID
MinioSecretKey string // MinIO secret access key
MinioUseSSL bool // Whether to use SSL for MinIO connection
MinioRegion string // MinIO region
MinioBucket string // MinIO bucket name (default: "opplens")
MinioTimeout time.Duration // Timeout for MinIO operations
}
// DefaultConfig returns a Config with sensible defaults.
func DefaultConfig() *Config {
return &Config{
APITimeout: 120 * time.Second,
APIRetryCount: 2,
APIRetryDelay: 3 * time.Second,
MinioBucket: "opplens",
MinioRegion: "us-east-1",
MinioUseSSL: false,
MinioTimeout: 30 * time.Second,
}
}
// Validate checks that all required configuration fields are present.
// Use this when both HTTP API and MinIO storage are needed.
func (c *Config) Validate() error {
if c.APIBaseURL == "" {
return errors.New("ai_summarizer: APIBaseURL is required")
}
return c.ValidateStorage()
}
// ValidateStorage checks only the MinIO storage-related configuration fields.
// Use this when only the storage client is needed (no HTTP API).
func (c *Config) ValidateStorage() error {
if c.MinioEndpoint == "" {
return errors.New("ai_summarizer: MinioEndpoint is required")
}
if c.MinioAccessKey == "" {
return errors.New("ai_summarizer: MinioAccessKey is required")
}
if c.MinioSecretKey == "" {
return errors.New("ai_summarizer: MinioSecretKey is required")
}
if c.MinioBucket == "" {
return fmt.Errorf("ai_summarizer: MinioBucket is required")
}
return nil
}
// ValidateAPI checks only the HTTP API-related configuration fields.
// Use this when only the HTTP client is needed (no MinIO storage).
func (c *Config) ValidateAPI() error {
if c.APIBaseURL == "" {
return errors.New("ai_summarizer: APIBaseURL is required")
}
return nil
}