Documentation ¶
Overview ¶
Package utils contains various utilities
Index ¶
- Variables
- func AssetsFromTarGz(tmpDir, assetsBase string) error
- func AssetsToTarGz(assetsDir, gzipFile string) error
- func ByteToHr(b int64) string
- func CalcSize(path string) (int64, error)
- func CreateSSPak(sspakFile string, files []string) error
- func DownloadToFile(url, filepath string) error
- func ExtractSSPak(sspakFile, outDir string) error
- func GithubLatest(repo, name string) (string, string, string, error)
- func GithubUpdate(repo, appName, currentVersion string) (string, error)
- func GreaterThan(toVer, fromVer string) bool
- func GzipFile(file, output string) error
- func HasEnoughSpace(location string, requiredSize int64) error
- func IsDir(path string) bool
- func IsFile(path string) bool
- func MkDirIfNotExists(path string) error
- func MySQLCreateDB(dropDatabase bool) error
- func MySQLDumpToGz(gzipFile string) error
- func MySQLLoadFromGz(gzipSQLFile string) error
- func ReplaceFile(dst, src string) error
- func TarGZCompress(inputFilePath, outputFilePath string) (err error)
- func TarGZExtract(inputFilePath, outputFilePath string) (err error)
- func Unzip(src string, dest string) ([]string, error)
- type Release
- type Releases
Constants ¶
This section is empty.
Variables ¶
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.
var AllowPrereleases = false
AllowPrereleases defines whether pre-releases may be included
Functions ¶
func AssetsFromTarGz ¶
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 ¶
AssetsToTarGz creates a tar.gz from the assets folder
func CreateSSPak ¶
CreateSSPak creates a regular POSIX tar file from a database and an assets archive
func DownloadToFile ¶
DownloadToFile downloads a URL to a file
func ExtractSSPak ¶
ExtractSSPak extracts a SSPak (tar) file
func GithubLatest ¶
GithubLatest fetches the latest release info & returns release tag, filename & download url
func GithubUpdate ¶
GithubUpdate the running binary with the latest release binary from Github
func GreaterThan ¶
GreaterThan compares the current version to a different version returning < 1 not upgradeable
func HasEnoughSpace ¶
HasEnoughSpace will return an error message if the provided location does not have sufficient storage space
func MkDirIfNotExists ¶
MkDirIfNotExists will create a directory if it doesn't exist
func MySQLCreateDB ¶
MySQLCreateDB a database, optionally dropping it
func MySQLDumpToGz ¶
MySQLDumpToGz uses mysqldump to stream a database dump directly into a gzip file
func MySQLLoadFromGz ¶
MySQLLoadFromGz loads a GZ database file into the database, streaming the gz file to the mysql cli.
func ReplaceFile ¶
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 ¶
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 ¶
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.
Types ¶
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