core

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: GPL-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// Common errors
	ErrServiceNotConfigured = errors.New("service is not configured")
	ErrNilResponse          = errors.New("received nil response from server")
	ErrContextCanceled      = errors.New("context canceled")

	// Default timeouts
	DefaultTimeout     = 30 * time.Second // Increased from 15s to 30s
	DefaultLongTimeout = 60 * time.Second // Added for services that need longer timeouts
)

Functions

This section is empty.

Types

type ServiceCore

type ServiceCore struct {
	Type           string
	DisplayName    string
	Description    string
	DefaultURL     string
	ApiKey         string
	HealthEndpoint string
	Timeout        time.Duration // Added configurable timeout
	// contains filtered or unexported fields
}

func (*ServiceCore) CacheUpdateStatus added in v0.3.0

func (s *ServiceCore) CacheUpdateStatus(ctx context.Context, baseURL string, updateAvailable bool, ttl time.Duration) error

CacheUpdateStatus stores update availability in the dedicated update cache key.

func (*ServiceCore) CacheVersion

func (s *ServiceCore) CacheVersion(ctx context.Context, baseURL, version string, ttl time.Duration) error

CacheVersion stores the version in cache with the specified TTL

func (*ServiceCore) ConcurrentRequest

func (s *ServiceCore) ConcurrentRequest(requests []func() (any, error)) []any

ConcurrentRequest executes multiple requests concurrently and returns their results

func (*ServiceCore) CreateHealthResponse

func (s *ServiceCore) CreateHealthResponse(lastChecked time.Time, status string, message string, extras ...map[string]any) models.ServiceHealth

CreateHealthResponse creates a standardized health response

func (*ServiceCore) DoRequest added in v0.3.0

func (s *ServiceCore) DoRequest(ctx context.Context, method string, url string, headers map[string]string, body []byte) (*http.Response, error)

DoRequest makes an HTTP request with the provided context, method, and optional body. Uses the shared HTTP client pool + service-specific timeout.

func (*ServiceCore) GetCachedVersion

func (s *ServiceCore) GetCachedVersion(ctx context.Context, baseURL, apiKey string, fetchVersion func(string, string) (string, error)) (string, error)

GetCachedVersion attempts to get version from cache or fetches it if not found

func (*ServiceCore) GetUpdateStatusFromCache added in v0.3.0

func (s *ServiceCore) GetUpdateStatusFromCache(ctx context.Context, baseURL string) bool

GetUpdateStatusFromCache retrieves the update status from cache.

func (*ServiceCore) GetUpdateStatusFromCacheWithFound added in v0.3.0

func (s *ServiceCore) GetUpdateStatusFromCacheWithFound(ctx context.Context, baseURL string) (bool, bool)

GetUpdateStatusFromCacheWithFound retrieves the update status from cache and reports whether a value existed.

func (*ServiceCore) GetVersionFromCache

func (s *ServiceCore) GetVersionFromCache(ctx context.Context, baseURL string) string

GetVersionFromCache retrieves the version from cache

func (*ServiceCore) ReadBody

func (s *ServiceCore) ReadBody(resp *http.Response) ([]byte, error)

ReadBody reads and returns the response body

func (*ServiceCore) SetDB added in v0.3.0

func (s *ServiceCore) SetDB(db *database.DB)

SetDB sets the database instance for the service

func (*ServiceCore) SetTimeout added in v0.3.0

func (s *ServiceCore) SetTimeout(timeout time.Duration)

SetTimeout sets a custom timeout for the service

Jump to

Keyboard shortcuts

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