sdk

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltinConfigNames

func BuiltinConfigNames() []string

func BuiltinMirrorNames

func BuiltinMirrorNames() []string

func DefaultStorePath

func DefaultStorePath() (string, error)

func RenderTemplate

func RenderTemplate(pattern string, vars TemplateVars) (string, error)

Types

type BuiltinConfig

type BuiltinConfig struct {
	Name    string
	Aliases []string
	Source  BuiltinConfigSource
	Section cfgpkg.SDKSection
}

func BuiltinConfigs

func BuiltinConfigs(source BuiltinConfigSource) []BuiltinConfig

func FindBuiltinConfig

func FindBuiltinConfig(name string, source BuiltinConfigSource) (BuiltinConfig, bool)

type BuiltinConfigSource

type BuiltinConfigSource string
const (
	BuiltinConfigOfficial BuiltinConfigSource = "official"
	BuiltinConfigMirror   BuiltinConfigSource = "mirror"
	BuiltinConfigAliyun   BuiltinConfigSource = "aliyun"
	BuiltinConfigHuawei   BuiltinConfigSource = "huawei"
	BuiltinConfigZulu     BuiltinConfigSource = "zulu"
)

type CachedIndexInfo

type CachedIndexInfo struct {
	SDK       string
	Versions  int
	SourceURL string
	FetchedAt time.Time
	Path      string
	Cached    bool
}

type Config

type Config struct {
	Name            string
	Aliases         []string
	SDKTarget       string
	TargetTemplate  string
	URLTemplate     string
	IndexURL        string
	IndexFormat     string
	IndexParser     string
	IndexPathPrefix string
	FilenamePattern string
	StripComponents int
	OS              string
	Arch            string
	Ext             string
	OSMap           map[string]string
	ArchMap         map[string]string
	ExtMap          map[string]string
}

func ResolveConfig

func ResolveConfig(file *cfgpkg.File, name string, opts ResolveConfigOptions) (Config, error)

type DownloadRequest

type DownloadRequest struct {
	URL      string
	CacheDir string
	SDK      string
	Version  string
	Filename string

	ClientOpts  client.Options
	CacheMirror cachemirror.Options
	Progress    func(size int64) io.Writer
}

type DownloadResult

type DownloadResult struct {
	Path      string
	FromCache bool
	Resumed   bool
	Size      int64
	ETag      string
	Modified  string
}

func DownloadArchive

func DownloadArchive(ctx context.Context, req DownloadRequest) (DownloadResult, error)

type DownloaderFunc

type DownloaderFunc func(context.Context, DownloadRequest) (DownloadResult, error)

type HTMLParseOptions

type HTMLParseOptions struct {
	SDK             string
	SourceURL       string
	IndexPathPrefix string
	FilenamePattern string
	URLTemplate     string
	OS              string
	Arch            string
	Ext             string
	Now             func() time.Time
}

type Index

type Index struct {
	Schema    int         `json:"schema"`
	SDK       string      `json:"sdk"`
	SourceURL string      `json:"source_url"`
	FetchedAt time.Time   `json:"fetched_at"`
	Items     []IndexItem `json:"items"`
}

func ParseHTMLIndex

func ParseHTMLIndex(body io.Reader, opts HTMLParseOptions) (Index, error)

func ParseJSONIndex

func ParseJSONIndex(body io.Reader, parser string, opts JSONParseOptions) (Index, error)

type IndexCache

type IndexCache struct {
	Dir string
}

func (IndexCache) Clear

func (c IndexCache) Clear(name string) error

func (IndexCache) ClearAll

func (c IndexCache) ClearAll() error

func (IndexCache) ClearForSource

func (c IndexCache) ClearForSource(name, sourceURL string) error

func (IndexCache) List

func (c IndexCache) List() ([]CachedIndexInfo, error)

func (IndexCache) Load

func (c IndexCache) Load(name string) (Index, error)

func (IndexCache) LoadForSource

func (c IndexCache) LoadForSource(name, sourceURL string) (Index, error)

func (IndexCache) Path

func (c IndexCache) Path(name string) string

func (IndexCache) PathForSource

func (c IndexCache) PathForSource(name, sourceURL string) string

func (IndexCache) Save

func (c IndexCache) Save(index Index) error

type IndexFile

type IndexFile struct {
	OS       string `json:"os"`
	Arch     string `json:"arch"`
	Ext      string `json:"ext"`
	URL      string `json:"url"`
	Filename string `json:"filename"`
}

func SelectFile

func SelectFile(item IndexItem, osName, arch, ext string) (IndexFile, error)

type IndexItem

type IndexItem struct {
	Version string      `json:"version"`
	Stable  bool        `json:"stable"`
	Files   []IndexFile `json:"files"`
}

func SelectVersion

func SelectVersion(index Index, target Target) (IndexItem, error)

type IndexRefreshEvent

type IndexRefreshEvent struct {
	Stage    IndexRefreshStage
	SDK      string
	URL      string
	Format   string
	Parser   string
	Versions int
	Files    int
	Err      error
}

type IndexRefreshStage

type IndexRefreshStage string
const (
	IndexRefreshFetchStart  IndexRefreshStage = "fetch_start"
	IndexRefreshFetchDone   IndexRefreshStage = "fetch_done"
	IndexRefreshParseStart  IndexRefreshStage = "parse_start"
	IndexRefreshParseDone   IndexRefreshStage = "parse_done"
	IndexRefreshParseFailed IndexRefreshStage = "parse_failed"
	IndexRefreshCacheHit    IndexRefreshStage = "cache_hit"
)

type InstallOptions

type InstallOptions struct {
	Force          bool
	Progress       func(size int64) io.Writer
	OnStart        func(target string, version string, host string)
	OnArchiveReady func(result DownloadResult)
	OnExtractStart func(archivePath string, installPath string)
}

type InstallResult

type InstallResult struct {
	Name    string
	Version string
	Path    string
	URL     string
	Cached  bool
	Resumed bool
}

type InstalledEntry

type InstalledEntry struct {
	Name            string    `json:"name"`
	Version         string    `json:"version"`
	Path            string    `json:"path"`
	URL             string    `json:"url"`
	Filename        string    `json:"filename"`
	OS              string    `json:"os"`
	Arch            string    `json:"arch"`
	Ext             string    `json:"ext"`
	InstalledAt     time.Time `json:"installed_at"`
	StripComponents int       `json:"strip_components"`
}

type InstalledSDKNode

type InstalledSDKNode struct {
	Versions map[string]InstalledEntry `json:"versions"`
}

type InstalledStore

type InstalledStore struct {
	Schema    int                         `json:"schema"`
	Installed map[string]InstalledSDKNode `json:"installed"`
}

type JSONParseOptions

type JSONParseOptions struct {
	SDK       string
	SourceURL string
	Now       func() time.Time
}

type PlatformOptions added in v1.7.5

type PlatformOptions struct {
	OS   string
	Arch string
}

type RemoveResult

type RemoveResult struct {
	Name    string
	Version string
	Path    string
	Missing bool
}

type ResolveConfigOptions

type ResolveConfigOptions struct {
	GOOS   string
	GOARCH string
}

type SDKDownloadOptions added in v1.7.5

type SDKDownloadOptions struct {
	Platform  PlatformOptions
	OutputDir string
	Progress  func(size int64) io.Writer
	OnStart   func(target string, version string, host string, goos string, goarch string)
}

type SDKDownloadResult added in v1.7.5

type SDKDownloadResult struct {
	Name     string
	Version  string
	Path     string
	URL      string
	Filename string
	OS       string
	Arch     string
	Ext      string
	Cached   bool
	Resumed  bool
}

type SearchOptions

type SearchOptions struct {
	Keywords []string
	Number   int
	Sort     string
}

type SearchResult

type SearchResult struct {
	SDK      string `json:"sdk"`
	Version  string `json:"version"`
	Stable   bool   `json:"stable"`
	OS       string `json:"os"`
	Arch     string `json:"arch"`
	Ext      string `json:"ext"`
	Filename string `json:"filename,omitempty"`
	URL      string `json:"url,omitempty"`
}

type Service

type Service struct {
	Config      *cfgpkg.File
	Store       Store
	IndexCache  IndexCache
	ClientOpts  client.Options
	CacheMirror cachemirror.Options
	GOOS        string
	GOARCH      string
	Now         func() time.Time
	Downloader  DownloaderFunc

	OnIndexRefresh func(IndexRefreshEvent)
}

func (Service) ClearAllIndexes

func (s Service) ClearAllIndexes() error

func (Service) ClearIndex

func (s Service) ClearIndex(name string) error

func (Service) Download added in v1.7.5

func (s Service) Download(ctx context.Context, rawTarget string, opts SDKDownloadOptions) (SDKDownloadResult, error)

func (Service) DownloadMany added in v1.7.5

func (s Service) DownloadMany(ctx context.Context, targets []string, opts SDKDownloadOptions) ([]SDKDownloadResult, error)

func (Service) Install

func (s Service) Install(ctx context.Context, rawTarget string, opts InstallOptions) (InstallResult, error)

func (Service) InstallMany

func (s Service) InstallMany(ctx context.Context, targets []string, opts InstallOptions) ([]InstallResult, error)

func (Service) List

func (s Service) List(name string) ([]InstalledEntry, error)

func (Service) ListIndexes

func (s Service) ListIndexes() ([]CachedIndexInfo, error)

func (Service) Path added in v1.7.4

func (s Service) Path(rawTarget string) (InstalledEntry, error)

func (Service) RefreshAllIndexes

func (s Service) RefreshAllIndexes(ctx context.Context) ([]Index, error)

func (Service) RefreshIndex

func (s Service) RefreshIndex(ctx context.Context, name string) (Index, error)

func (Service) Remove

func (s Service) Remove(rawTarget string) (RemoveResult, error)

func (Service) SearchIndex

func (s Service) SearchIndex(name string, opts SearchOptions) ([]SearchResult, error)

func (Service) ShowIndex

func (s Service) ShowIndex(name string) (Index, error)

type Store

type Store struct {
	Path string
}

func (Store) List

func (s Store) List(name string) ([]InstalledEntry, error)

func (Store) Load

func (s Store) Load() (InstalledStore, error)

func (Store) Record

func (s Store) Record(entry InstalledEntry) error

func (Store) Remove

func (s Store) Remove(name, version string) (InstalledEntry, error)

func (Store) Save

func (s Store) Save(store InstalledStore) error

type Target

type Target struct {
	Raw     string
	Name    string
	Version string
	Kind    VersionKind
}

func ParseTarget

func ParseTarget(input string) (Target, error)

type TemplateVars

type TemplateVars struct {
	Name    string
	Version string
	OS      string
	Arch    string
	Ext     string
}

type VersionKind

type VersionKind string
const (
	VersionLatest VersionKind = "latest"
	VersionExact  VersionKind = "exact"
	VersionPrefix VersionKind = "prefix"
)

Jump to

Keyboard shortcuts

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