2025-04-25 20:53:07 +05:30
|
|
|
package registry
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// RegistryType represents different package registries
|
|
|
|
|
type RegistryType string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
RegistryNPM RegistryType = "npm"
|
2025-04-30 14:26:38 +05:30
|
|
|
RegistryPNPM RegistryType = "pnpm"
|
2025-04-25 20:53:07 +05:30
|
|
|
RegistryPyPI RegistryType = "pypi"
|
|
|
|
|
RegistryGo RegistryType = "go"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// FetcherFactory creates appropriate fetchers based on registry type
|
|
|
|
|
type FetcherFactory struct {
|
|
|
|
|
timeout time.Duration
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewFetcherFactory creates a new factory for registry fetchers
|
|
|
|
|
func NewFetcherFactory(timeout time.Duration) *FetcherFactory {
|
|
|
|
|
return &FetcherFactory{
|
|
|
|
|
timeout: timeout,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateFetcher returns a fetcher for the specified registry type
|
|
|
|
|
func (ff *FetcherFactory) CreateFetcher(registryType RegistryType) (Fetcher, error) {
|
|
|
|
|
switch registryType {
|
2025-04-30 14:26:38 +05:30
|
|
|
case RegistryNPM, RegistryPNPM:
|
2025-04-25 20:53:07 +05:30
|
|
|
return NewNpmFetcher(ff.timeout), nil
|
|
|
|
|
default:
|
|
|
|
|
return nil, fmt.Errorf("unsupported registry type: %s", registryType)
|
|
|
|
|
}
|
|
|
|
|
}
|