commons

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultPaginationLimit = 1000
View Source
const LATEST_TAG = "nightly"
View Source
const WINDOWS = "windows"

Variables

View Source
var ErrInvalidCursor = errors.New("invalid pagination cursor")
View Source
var ErrInvalidLimit = errors.New("limit cannot be negative")
View Source
var ErrMixedPagination = errors.New(
	"cannot mix forward pagination (first, after) with backward pagination (last, before)")

Functions

func ComputePage

func ComputePage(
	first *int, last *int, after *string, before *string, total int,
) (offset int, limit int, err error)

Compute the pagination parameters given the GraphQL connection parameters.

func ConfigureLog

func ConfigureLog(level slog.Leveler)

func DecodeCursor

func DecodeCursor(base64Cursor string, total int) (int, error)

Decode the integer offset from a base64 string.

func EncodeCursor

func EncodeCursor(offset int) string

Encode the integer offset into a base64 string.

func ExtractTarGz added in v1.1.2

func ExtractTarGz(archive []byte, destDir string) error

Extract a tar.gz archive to a destination directory

func ExtractZip added in v1.1.2

func ExtractZip(archive []byte, destDir string) error

Extract a zip archive to a destination directory

Types

type AnvilConfig added in v1.1.2

type AnvilConfig struct {
	AssetAnvil  ReleaseAsset `json:"asset_anvil"`
	LatestCheck string       `json:"latest_check"`
}

func LoadAnvilConfig added in v1.1.2

func LoadAnvilConfig(path string) (*AnvilConfig, error)

func NewAnvilConfig added in v1.1.2

func NewAnvilConfig(ra ReleaseAsset) *AnvilConfig

func (*AnvilConfig) SaveAnvilConfig added in v1.1.2

func (a *AnvilConfig) SaveAnvilConfig(path string) error

type AnvilRelease added in v1.1.2

type AnvilRelease struct {
	Namespace      string
	Repository     string
	ConfigFilename string
	Client         *github.Client
}

Anvil implementation from HandleRelease

func (*AnvilRelease) DownloadAsset added in v1.1.2

func (a *AnvilRelease) DownloadAsset(ctx context.Context, release *ReleaseAsset) (string, error)

DownloadAsset implements HandleRelease.

func (*AnvilRelease) ExtractAsset added in v1.1.2

func (a *AnvilRelease) ExtractAsset(archive []byte, filename string, destDir string) error

func (AnvilRelease) FormatNameRelease added in v1.1.2

func (a AnvilRelease) FormatNameRelease(_, goos, goarch, _ string) string

FormatNameRelease implements HandleRelease.

func (*AnvilRelease) GetLatestReleaseCompatible added in v1.1.2

func (a *AnvilRelease) GetLatestReleaseCompatible(ctx context.Context) (*ReleaseAsset, error)

GetLatestReleaseCompatible implements HandleRelease.

func (*AnvilRelease) ListRelease added in v1.1.2

func (a *AnvilRelease) ListRelease(ctx context.Context) ([]ReleaseAsset, error)

ListRelease implements HandleRelease.

func (AnvilRelease) PlatformCompatible added in v1.1.2

func (a AnvilRelease) PlatformCompatible() (string, error)

PlatformCompatible implements HandleRelease.

func (*AnvilRelease) Prerequisites added in v1.1.2

func (a *AnvilRelease) Prerequisites(ctx context.Context) error

Prerequisites implements HandleRelease.

func (AnvilRelease) SaveConfigOnDefaultLocation added in v1.1.2

func (a AnvilRelease) SaveConfigOnDefaultLocation(config *AnvilConfig) error

func (AnvilRelease) TryLoadConfig added in v1.1.2

func (a AnvilRelease) TryLoadConfig() (*AnvilConfig, error)

type HandleRelease added in v1.1.2

type HandleRelease interface {
	// Name basead on version, arch, os with prefix
	FormatNameRelease(prefix, goos, goarch, version string) string
	// Check if the platform is compatible with the library and return the name of the release
	PlatformCompatible() (string, error)
	// List all releases from the repository
	ListRelease(ctx context.Context) ([]ReleaseAsset, error)
	// Get the latest release compatible with the platform
	GetLatestReleaseCompatible(ctx context.Context) (*ReleaseAsset, error)
	// Check prerequisites for the library
	Prerequisites(ctx context.Context) error
	// Download the asset from the release
	DownloadAsset(ctx context.Context, release *ReleaseAsset) (string, error)
	// Extract the asset from the archive
	ExtractAsset(archive []byte, filename string, destDir string) error
}

Interface for handle libraries on GitHub

func NewAnvilRelease added in v1.1.2

func NewAnvilRelease() HandleRelease

type PageResult

type PageResult[T any] struct {
	Total  uint64
	Offset uint64
	Rows   []T
}

type ReleaseAsset added in v1.1.2

type ReleaseAsset struct {
	Tag      string `json:"tag"`
	AssetId  int64  `json:"asset_id"`
	Filename string `json:"filename"`
	Url      string `json:"url"`
	Path     string `json:"path"`
}

ReleaseAsset represents a release asset from GitHub

func GetAssetsFromLastReleaseGitHub added in v1.1.2

func GetAssetsFromLastReleaseGitHub(ctx context.Context, client *github.Client, namespace, repository string, tag string) ([]ReleaseAsset, error)

Get assets of latest release or prerelease from GitHub

Jump to

Keyboard shortcuts

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