util

package
v0.1.106 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExceeded = errors.New("Rate-Limit Exceeded")
	ErrNotFound = errors.New("Not Found")
)

ErrExceeded should be returned if we need to rerun the function

Functions

func AirDateWithAiredCheck

func AirDateWithAiredCheck(dt string, dateFormat string, allowSameDay bool) (airDate time.Time, isAired bool)

AirDateWithAiredCheck returns the aired date and flag if it was already aired

func ApplyColor

func ApplyColor(text string, color string) (coloredText string)

ApplyColor applies a color to a text to use in Kodi skin

func Bod

func Bod(t time.Time) time.Time

Bod returns the start of a day for specific date

func Copy

func Copy(src, dst string, followSymlinks bool) (string, error)

Copy data and mode bits ("cp src dst"). Return the file's destination.

The destination may be a directory.

If followSymlinks is false, symlinks won't be followed. This resembles GNU's "cp -P src dst".

If source and destination are the same file, a SameFileError will be raised.

func CopyFile

func CopyFile(src, dst string, followSymlinks bool) error

CopyFile Copy data from src to dst

If followSymlinks is not set and src is a symbolic link, a new symlink will be created instead of copying the file it points to.

func CopyMode

func CopyMode(src, dst string, followSymlinks bool) error

CopyMode bits from src to dst.

If followSymlinks is false, symlinks aren't followed if and only if both `src` and `dst` are symlinks. If `lchmod` isn't available and both are symlinks this does nothing. (I don't think lchmod is available in Go)

func CopyTree

func CopyTree(src, dst string, options *CopyTreeOptions) error

CopyTree ...

func DecodeFileURL

func DecodeFileURL(u string) (ret string)

DecodeFileURL decodes file path from url

func Difference

func Difference(arrs ...interface{}) (reflect.Value, bool)

Difference ...

func Distinct

func Distinct(arr interface{}) (reflect.Value, bool)

Distinct ...

func EffectiveDir

func EffectiveDir(p string) string

EffectiveDir is checking argument path and returning closest folder.

func EncodeFileURL

func EncodeFileURL(u string) (ret string)

EncodeFileURL encode file path into proper url

func FileExists

func FileExists(name string) bool

FileExists check for file existence in a simple way

func FileWithoutExtension

func FileWithoutExtension(name string) string

FileWithoutExtension returns file without extension

func FreeMemory

func FreeMemory()

FreeMemory runs FreeOSMemory() only

func FreeMemoryGC

func FreeMemoryGC()

FreeMemoryGC runs FreeOSMemory() and GC()

func GetRealPath

func GetRealPath(path string) (ret string)

func GetTimeFromFile

func GetTimeFromFile(timeFile string) (time.Time, error)

func HasAudioExt

func HasAudioExt(filename string) bool

HasAudioExt searches different audio extensions in file name

func HasSubtitlesExt

func HasSubtitlesExt(filename string) bool

HasSubtitlesExt searches different subtitles extensions in file name

func IntSliceContains

func IntSliceContains(ary []int, q int) bool

IntSliceContains ...

func IsAudioExt

func IsAudioExt(ext string) bool

IsAudioExt checks if extension belong to Audio type

func IsNetworkPath

func IsNetworkPath(path string) bool

func IsSpecialPath

func IsSpecialPath(path string) bool

func IsSubtitlesExt

func IsSubtitlesExt(ext string) bool

IsSubtitlesExt checks if extension belong to Subtitles type

func IsSymlink(fi os.FileInfo) bool

IsSymlink ...

func IsTimePassed

func IsTimePassed(last time.Time, period time.Duration) bool

func IsValidPath

func IsValidPath(path string) bool

func IsWritablePath

func IsWritablePath(path string) error

IsWritablePath ...

func Max

func Max(a, b int) int

Max ...

func Min

func Min(a, b int) int

Min ...

func Move

func Move(src, dst string) (string, error)

Move a file from src to dst

Simply tries os.Rename first in case the file is getting moved on the same disk, and uses Copy() otherwise.

Does not follow symlinks when copying.

func NowInt

func NowInt() int

NowInt ...

func NowInt64

func NowInt64() int64

NowInt64 ...

func NowPlusSecondsInt

func NowPlusSecondsInt(seconds int) int

NowPlusSecondsInt ..

func PathExists

func PathExists(path string) bool

PathExists returns whether path exists in OS

func RandomString

func RandomString(length int) string

func SetTimeIntoFile

func SetTimeIntoFile(timeFile string) (time.Time, error)

func StrInterfaceToInt

func StrInterfaceToInt(t interface{}) (i int)

StrInterfaceToInt ...

func StringSliceContains

func StringSliceContains(ary []string, q string) bool

StringSliceContains ...

func ToFileName

func ToFileName(filename string) string

ToFileName ...

func TrailerURL

func TrailerURL(u string) (ret string)

TrailerURL returns trailer url, constructed for Kodi

func UTCBod

func UTCBod() time.Time

UTCBod returns the start of a day for Now().UTC()

Types

type AlreadyExistsError

type AlreadyExistsError struct {
	Dst string
}

AlreadyExistsError ...

func (AlreadyExistsError) Error

func (e AlreadyExistsError) Error() string

Error ...

type CopyTreeOptions

type CopyTreeOptions struct {
	Symlinks               bool
	IgnoreDanglingSymlinks bool
	CopyFunction           func(string, string, bool) (string, error)
	Ignore                 func(string, []fs.DirEntry) []string
}

CopyTreeOptions ...

type Locker

type Locker struct {
	// contains filtered or unexported fields
}

Locker wraps a map of mutexes. Each key locks separately.

func NewLocker

func NewLocker() *Locker

NewLocker returns an initalized M.

func (*Locker) Lock

func (m *Locker) Lock(key interface{}) Unlocker

Lock acquires a lock corresponding to this key. This method will never return nil and Unlock() must be called to release the lock when done.

type NotADirectoryError

type NotADirectoryError struct {
	Src string
}

NotADirectoryError ...

func (NotADirectoryError) Error

func (e NotADirectoryError) Error() string

Error ...

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

A RateLimiter limits the rate at which an action can be performed. It applies neither smoothing (like one could achieve in a token bucket system) nor does it offer any conception of warmup, wherein the rate of actions granted are steadily increased until a steady throughput equilibrium is reached.

func NewRateLimiter

func NewRateLimiter(limit int, interval time.Duration, parallelCount int) *RateLimiter

NewRateLimiter creates a new rate limiter for the limit and interval.

func (*RateLimiter) Call

func (r *RateLimiter) Call(f func() error)

Call ...

func (*RateLimiter) CoolDown

func (r *RateLimiter) CoolDown(headers http.Header)

CoolDown is checking HTTP headers if we need to wait

func (*RateLimiter) Enter

func (r *RateLimiter) Enter()

Enter blocks parallen channel for simultaneous connections limitation

func (*RateLimiter) ForceWait

func (r *RateLimiter) ForceWait()

ForceWait is forcing rate limit if we have an external cause (like Response from API).

func (*RateLimiter) Leave

func (r *RateLimiter) Leave()

Leave removes channel usage

func (*RateLimiter) Try

func (r *RateLimiter) Try() (ok bool, remaining time.Duration)

Try returns true if under the rate limit, or false if over and the remaining time before the rate limit expires.

func (*RateLimiter) Wait

func (r *RateLimiter) Wait()

Wait blocks if the rate limit has been reached. Wait offers no guarantees of fairness for multiple actors if the allowed rate has been temporarily exhausted.

type SameFileError

type SameFileError struct {
	Src string
	Dst string
}

SameFileError ...

func (SameFileError) Error

func (e SameFileError) Error() string

Error ...

type SpecialFileError

type SpecialFileError struct {
	File     string
	FileInfo os.FileInfo
}

SpecialFileError ...

func (SpecialFileError) Error

func (e SpecialFileError) Error() string

Error ...

type Unlocker

type Unlocker interface {
	Unlock()
}

Unlocker provides an Unlock method to release the lock.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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