Documentation ¶
Index ¶
- Constants
- Variables
- func BytesToString(b []byte) string
- func Command(command string, a ...string) (output string, err error)
- func CopyDir(source string, dest string) (err error)
- func CopyFile(source string, destination string) error
- func Deserialize(str string, m interface{}) error
- func DeserializeBytes(b []byte, m interface{}) error
- func DirectoryExists(dir string) bool
- func DownloadZip(zipURL string, newDir string) (string, error)
- func Exists(dir string) bool
- func FindLower(a, b int) int
- func GetParentDir(targetDirectory string) string
- func HTMLEscape(s string) string
- func Install(remoteFileZip string, targetDirectory string) (installedDirectory string, err error)
- func MustCommand(command string, a ...string) (output string)
- func Random(n int) []byte
- func RandomString(n int) string
- func RemoveFile(filePath string) error
- func Serialize(m interface{}) (string, error)
- func SerializeBytes(m interface{}) ([]byte, error)
- func StringToBytes(s string) []byte
- func TypeByExtension(fullfilename string) (t string)
- func Unzip(archive string, target string) (string, error)
- func WatchDirectoryChanges(paths []string, evt func(filename string), logger *logger.Logger)
- type BufferPool
- type Cmd
- type ITick
- type Ticker
Constants ¶
const (
// ContentBINARY is the string of "application/octet-stream response headers
ContentBINARY = "application/octet-stream"
)
Variables ¶
var ( // ErrNoZip returns an error with message: 'While creating file '+filename'. It's not a zip' ErrNoZip = errors.New("While installing file '%s'. It's not a zip") // ErrFileOpen returns an error with message: 'While opening a file. Trace: +specific error' ErrFileOpen = errors.New("While opening a file. Trace: %s") // ErrFileCreate returns an error with message: 'While creating a file. Trace: +specific error' ErrFileCreate = errors.New("While creating a file. Trace: %s") // ErrFileRemove returns an error with message: 'While removing a file. Trace: +specific error' ErrFileRemove = errors.New("While removing a file. Trace: %s") // ErrFileCopy returns an error with message: 'While copying files. Trace: +specific error' ErrFileCopy = errors.New("While copying files. Trace: %s") // ErrFileDownload returns an error with message: 'While downloading from +specific url. Trace: +specific error' ErrFileDownload = errors.New("While downloading from %s. Trace: %s") // ErrDirCreate returns an error with message: 'Unable to create directory on '+root dir'. Trace: +specific error ErrDirCreate = errors.New("Unable to create directory on '%s'. Trace: %s") )
var (
// AssetsDirectory the path which iris saves some assets came from the internet ( used in iris control plugin (to download the html,css,js) and for iris command line tool to download the packages)
AssetsDirectory = ""
)
var ( // PathSeparator is the string of os.PathSeparator PathSeparator = string(os.PathSeparator) )
Functions ¶
func BytesToString ¶
BytesToString accepts bytes and returns their string presentation instead of string() this method doesn't generate memory allocations, BUT it is not safe to use anywhere because it points this helps on 0 memory allocations
func CopyDir ¶
CopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist.
Note: the CopyDir function was not written by me, but its working well
func CopyFile ¶
CopyFile copy a file, accepts full path of the source and full path of destination, if file exists it's overrides it this function doesn't checks for permissions and all that, it returns an error if didn't worked
func Deserialize ¶
Deserialize accepts an encoded string and a data struct which will be filled with the desierialized string using gob decoder
func DeserializeBytes ¶
DeserializeBytes converts the bytes to an object using gob decoder
func DirectoryExists ¶
DirectoryExists returns true if a directory(or file) exists, otherwise false
func DownloadZip ¶
DownloadZip downloads a zip file returns the downloaded filename and an error.
An indicator is always shown up to the terminal, so the user will know if (a plugin) try to download something
func GetParentDir ¶
GetParentDir returns the parent directory(string) of the passed targetDirectory (string)
func HTMLEscape ¶
HTMLEscape returns a string which has no valid html code
func Install ¶
Install is just the flow of: downloadZip -> unzip -> removeFile(zippedFile) accepts 2 parameters
first parameter is the remote url file zip second parameter is the target directory returns a string(installedDirectory) and an error
(string) installedDirectory is the directory which the zip file had, this is the real installation path, you don't need to know what it's because these things maybe change to the future let's keep it to return the correct path. the installedDirectory is not empty when the installation is succed, the targetDirectory is not already exists and no error happens the installedDirectory is empty when the installation is already done by previous time or an error happens
func MustCommand ¶
MustCommand executes a command in shell and returns it's output, it's block version. It panics on an error
func Random ¶
Random takes a parameter (int) and returns random slice of byte ex: var randomstrbytes []byte; randomstrbytes = utils.Random(32)
func RandomString ¶
RandomString accepts a number(10 for example) and returns a random string using simple but fairly safe random algorithm
func RemoveFile ¶
RemoveFile removes a file or directory and returns an error, if any
func Serialize ¶
Serialize serialize any type to gob bytes and after returns its the base64 encoded string
func SerializeBytes ¶
SerializeBytes serializa bytes using gob encoder and returns them
func StringToBytes ¶
StringToBytes accepts string and returns their []byte presentation instead of byte() this method doesn't generate memory allocations, BUT it is not safe to use anywhere because it points this helps on 0 memory allocations
func TypeByExtension ¶
TypeByExtension returns the MIME type associated with the file extension ext. The extension ext should begin with a leading dot, as in ".html". When ext has no associated type, TypeByExtension returns "".
Extensions are looked up first case-sensitively, then case-insensitively.
The built-in table is small but on unix it is augmented by the local system's mime.types file(s) if available under one or more of these names:
/etc/mime.types /etc/apache2/mime.types /etc/apache/mime.types
On Windows, MIME types are extracted from the registry.
Text types have the charset parameter set to "utf-8" by default.
Types ¶
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
BufferPool implements a pool of bytes.Buffers in the form of a bounded channel. Pulled from the github.com/oxtoacart/bpool package (Apache licensed).
func NewBufferPool ¶
func NewBufferPool(size int) (bp *BufferPool)
NewBufferPool creates a new BufferPool bounded to the given size.
func (*BufferPool) Get ¶
func (bp *BufferPool) Get() (b *bytes.Buffer)
Get gets a Buffer from the BufferPool, or creates a new one if none are available in the pool.
func (*BufferPool) Put ¶
func (bp *BufferPool) Put(b *bytes.Buffer)
Put returns the given Buffer to the BufferPool.
type Cmd ¶
Cmd is a custom struch which 'implements' the *exec.Cmd
func CommandBuilder ¶
CommandBuilder creates a Cmd object and returns it accepts 2 parameters, one is optionally first parameter is the command (string) second variatic parameter is the argument(s) (slice of string)
the difference from the normal Command function is that you can re-use this Cmd, it doesn't execute until you call its Command function
func (*Cmd) AppendArguments ¶
AppendArguments appends the arguments to the exists
func (*Cmd) Arguments ¶
Arguments sets the command line arguments, including the command as Args[0]. If the args parameter is empty or nil, Run uses {Path}.
In typical use, both Path and args are set by calling Command.
func (*Cmd) Directory ¶
Directory sets the working directory of the command. If workingDirectory is the empty string, Run runs the command in the calling process's current directory.
func (*Cmd) ResetArguments ¶
ResetArguments resets the arguments
type ITick ¶
type ITick interface {
OnTick()
}
ITick is the interface which all ticker's listeners must implement
type Ticker ¶
type Ticker struct {
// contains filtered or unexported fields
}
Ticker is the timer which is used in cache
func (*Ticker) OnTick ¶
func (c *Ticker) OnTick(h func())
OnTick add event handlers/ callbacks which are called on each timer's tick