utils

package
v0.0.0-...-be2d47e Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package utils contains various utilities

Index

Constants

This section is empty.

Variables

View Source
var (
	// DBDumpWrapper is a map of database dump to gzip functions based on DB.Type
	DBDumpWrapper = map[string]func(string) error{
		"MySQL": MySQLDumpToGz,
	}

	// DBCreateWrapper is a map is database creation functions based on DB.Type
	DBCreateWrapper = map[string]func(bool) error{
		"MySQL": MySQLCreateDB,
	}

	// DBLoadWrapper is a map of database load-from-gzip functions based on DB.Type
	DBLoadWrapper = map[string]func(string) error{
		"MySQL": MySQLLoadFromGz,
	}
)

The DB wrappers serve to map the various database functions to their respective types. This provides flexibility in the calling function without having to duplicate code and wrap in a whole bunch of if/else statements.

View Source
var AllowPrereleases = false

AllowPrereleases defines whether pre-releases may be included

Functions

func AssetsFromTarGz

func AssetsFromTarGz(tmpDir, assetsBase string) error

AssetsFromTarGz extracts assets from a tar.gz. If an existing assets directory is found then the existing one is renamed assets.old, and then deleted after the process completes.

func AssetsToTarGz

func AssetsToTarGz(assetsDir, gzipFile string) error

AssetsToTarGz creates a tar.gz from the assets folder

func ByteToHr

func ByteToHr(b int64) string

ByteToHr returns a human readable size as a string

func CalcSize

func CalcSize(path string) (int64, error)

CalcSize returns the size of a directory or file

func CreateSSPak

func CreateSSPak(sspakFile string, files []string) error

CreateSSPak creates a regular POSIX tar file from a database and an assets archive

func DownloadToFile

func DownloadToFile(url, filepath string) error

DownloadToFile downloads a URL to a file

func ExtractSSPak

func ExtractSSPak(sspakFile, outDir string) error

ExtractSSPak extracts a SSPak (tar) file

func GithubLatest

func GithubLatest(repo, name string) (string, string, string, error)

GithubLatest fetches the latest release info & returns release tag, filename & download url

func GithubUpdate

func GithubUpdate(repo, appName, currentVersion string) (string, error)

GithubUpdate the running binary with the latest release binary from Github

func GreaterThan

func GreaterThan(toVer, fromVer string) bool

GreaterThan compares the current version to a different version returning < 1 not upgradeable

func GzipFile

func GzipFile(file, output string) error

GzipFile will compress an existing file with gzip and save it was output

func HasEnoughSpace

func HasEnoughSpace(location string, requiredSize int64) error

HasEnoughSpace will return an error message if the provided location does not have sufficient storage space

func IsDir

func IsDir(path string) bool

IsDir returns if a path is a directory

func IsFile

func IsFile(path string) bool

IsFile returns if a path is a file

func MkDirIfNotExists

func MkDirIfNotExists(path string) error

MkDirIfNotExists will create a directory if it doesn't exist

func MySQLCreateDB

func MySQLCreateDB(dropDatabase bool) error

MySQLCreateDB a database, optionally dropping it

func MySQLDumpToGz

func MySQLDumpToGz(gzipFile string) error

MySQLDumpToGz uses mysqldump to stream a database dump directly into a gzip file

func MySQLLoadFromGz

func MySQLLoadFromGz(gzipSQLFile string) error

MySQLLoadFromGz loads a GZ database file into the database, streaming the gz file to the mysql cli.

func ReplaceFile

func ReplaceFile(dst, src string) error

ReplaceFile replaces one file with another. Running files cannot be overwritten, so it has to be moved and the new binary saved to the original path. This requires read & write permissions to both the original file and directory. Note, on Windows it is not possible to delete a running program, so the old exe is renamed and moved to os.TempDir()

func TarGZCompress

func TarGZCompress(inputFilePath, outputFilePath string) (err error)

TarGZCompress creates a archive from the folder inputFilePath. Only adds the last directory in inputFilePath to the archive, not the whole path. It tries to create the directory structure outputFilePath contains if it doesn't exist. It returns potential errors to be checked or nil if everything works.

func TarGZExtract

func TarGZExtract(inputFilePath, outputFilePath string) (err error)

TarGZExtract extracts a archive from the file inputFilePath. It tries to create the directory structure outputFilePath contains if it doesn't exist. It returns potential errors to be checked or nil if everything works.

func Unzip

func Unzip(src string, dest string) ([]string, error)

Unzip will decompress a zip archive, moving all files and folders within the zip file (src) to an output directory (dest).

Types

type Release

type Release struct {
	Name string
	Tag  string
	URL  string
	Size int64
}

Release struct contains the file data for downloadable release

type Releases

type Releases []struct {
	Name       string `json:"name"`       // release name
	Tag        string `json:"tag_name"`   // release tag
	Prerelease bool   `json:"prerelease"` // Github pre-release
	Assets     []struct {
		BrowserDownloadURL string `json:"browser_download_url"`
		ID                 int64  `json:"id"`
		Name               string `json:"name"`
		Size               int64  `json:"size"`
	} `json:"assets"`
}

Releases struct for Github releases json

Jump to

Keyboard shortcuts

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