utils

package
v0.0.0-...-332fa53 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FileCreate = fsnotify.Create
	FileWrite  = fsnotify.Write
	FileRemove = fsnotify.Remove
	FileRename = fsnotify.Rename
)

Variables

View Source
var DefaultClient = http.DefaultClient

DefaultClient is the default client all http requests are fired from.

View Source
var Interrupt = new(interruptListener)

Interrupt watches the os.Signals for interruption signals and fires the callbacks when those happens. A call of its `FireNow` manually will fire and reset the registered interrupt handlers.

Functions

func Command

func Command(name string, args ...string) *exec.Cmd

Command returns the Cmd struct to execute the named program with the given arguments for windows.

func CommandWithCancel

func CommandWithCancel(name string, args ...string) (*exec.Cmd, context.CancelFunc)

CommandWithCancel same as `Command` but returns a canceletion function too.

func Dest

func Dest(dest string) string

Dest tries to resolve and returns a destination dir path.

func Download

func Download(url string, body io.Reader, options ...DownloadOption) ([]byte, error)

Download returns the body of "url". It uses the `http.DefaultClient` to download the resource specified by the "url" input argument.

func DownloadFile

func DownloadFile(repo, version, name string) ([]byte, error)

DownloadFile returns the contents of a github file inside a repository.

func DownloadReader

func DownloadReader(url string, body io.Reader, options ...DownloadOption) (io.ReadCloser, error)

DownloadReader returns a response reader.

func Exists

func Exists(path string) bool

Exists tries to report whether the local physical "path" exists.

func Export

func Export(destFile string, v interface{}) error

Export exports "v" to "destFile" system file. It creates it if it does not exist and overrides it if contains data.

func Ext

func Ext(s string) string

Ext returns the filepath extension of "s".

func FindMatches

func FindMatches(rootDir, pattern string, listDirectories bool) ([]string, error)

FindMatches find all matches of a "pattern" reclusively. Ordered by parent dir.

func FormatExecutable

func FormatExecutable(bin string) string

func GetAllFiles

func GetAllFiles(rootDir string) (files []string, err error)

GetAllFiles returns all files and directories from "rootDir". The return "files" as fullpaths.

func GetFilesDiff

func GetFilesDiff(rootDir string) (func() []string, error)

GetFilesDiff returns a function which collects new files or directories since `GetFilesDiff` called. Its return function's slice contains a relative to "rootDir" filenames.

func Import

func Import(sourceFile string, dest interface{}) error

Import decodes a file to "dest".

func InitClient

func InitClient(proxyAddr string)

InitClient initialize the global HTTP client.

func IsDir

func IsDir(path string) bool

IsDir reports whether a "path" is a filesystem directory.

func IsInsideDocker

func IsInsideDocker() bool

IsInsideDocker reports whether the iris-cli is running through a docker container.

func KillCommand

func KillCommand(cmd *exec.Cmd) error

func ListReleases

func ListReleases(repo string) []string

ListReleases lists all releases of a github "repo".

func NoOpReadCloser

func NoOpReadCloser(r io.Reader) io.ReadCloser

NoOpReadCloser wraps the "r" and returns a new io.ReadCloser which its `Close` does nothing.

func ReadJSON

func ReadJSON(url string, ptr interface{}) error

ReadJSON decodes a resource to "ptr".

func RegisterOnInterrupt

func RegisterOnInterrupt(cb func())

RegisterOnInterrupt registers a global function to call when CTRL+C/CMD+C pressed or a unix kill command received.

func SplitNameVersion

func SplitNameVersion(s string) (name string, version string)

SplitNameVersion accepts a string and returns its name and version.

func StartExecutable

func StartExecutable(dir, bin string, stdout, stderr io.Writer) (*exec.Cmd, error)

Types

type DownloadOption

type DownloadOption func(*http.Request) error

DownloadOption is the type of third, variadic input argument of the `Download` package-level function. Could change or read the request before use.

type Filter

type Filter func(name string) bool

type Watcher

type Watcher struct {
	AddFilter Filter

	Events chan []fsnotify.Event

	Dirs []string
	// contains filtered or unexported fields
}

func NewWatcher

func NewWatcher() (*Watcher, error)

func (*Watcher) Add

func (w *Watcher) Add(dir string) error

func (*Watcher) AddRecursively

func (w *Watcher) AddRecursively(root string) error

func (*Watcher) Close

func (w *Watcher) Close() error

func (*Watcher) Closed

func (w *Watcher) Closed() <-chan struct{}

func (*Watcher) Continue

func (w *Watcher) Continue() bool

func (*Watcher) Is

func (w *Watcher) Is(evt fsnotify.Event, op fsnotify.Op) bool

func (*Watcher) Pause

func (w *Watcher) Pause() bool

Jump to

Keyboard shortcuts

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