util

package
v0.0.0-...-29a3764 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2020 License: GPL-3.0 Imports: 23 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")
	ErrHTTP     = errors.New("HTTP error")
)

ErrExceeded should be returned if we need to rerun the function

View Source
var (
	// Version ...
	Version = "v0.0.1"
)

Functions

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 DefaultPeerID

func DefaultPeerID() string

DefaultPeerID return default PeerID

func DefaultUserAgent

func DefaultUserAgent() string

DefaultUserAgent ...

func Difference

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

Difference ...

func Distinct

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

Distinct ...

func EncodeFileURL

func EncodeFileURL(u string) (ret string)

EncodeFileURL encode file path into proper url

func FreeMemory

func FreeMemory()

FreeMemory runs FreeOSMemory() only

func FreeMemoryGC

func FreeMemoryGC()

FreeMemoryGC runs FreeOSMemory() and GC()

func GetContextHTTPHost

func GetContextHTTPHost(ctx *gin.Context) string

GetContextHTTPHost ...

func GetHTTPHost

func GetHTTPHost() string

GetHTTPHost ...

func GetListenAddr

func GetListenAddr(confAutoIP bool, confAutoPort bool, confInterfaces string, confPortMin int, confPortMax int) (listenIP, listenIPv6 string, listenPort int, disableIPv6 bool, err error)

GetListenAddr parsing configuration setted for interfaces and port range and returning IP, IPv6, and port

func GetTorrentVersion

func GetTorrentVersion() string

GetTorrentVersion returns version of GoTorrent, provided to compiler

func GetUserAndPeer

func GetUserAndPeer() (peerID, userAgent string)

GetUserAndPeer returns PeerID and UserAgent, according to Config settings. If not set - returns default values

func GetVersion

func GetVersion() string

GetVersion returns version, provided to compiler

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 InternalProxyURL

func InternalProxyURL() string

InternalProxyURL returns internal proxy url

func IsAudioExt

func IsAudioExt(ext string) bool

IsAudioExt checks if extension belong to Audio type

func IsSubtitlesExt

func IsSubtitlesExt(ext string) bool

IsSubtitlesExt checks if extension belong to Subtitles type

func IsSymlink(fi os.FileInfo) bool

IsSymlink ...

func LocalIP

func LocalIP() (net.IP, error)

LocalIP ...

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 PeerIDRandom

func PeerIDRandom(peer string) string

PeerIDRandom generates random peer id

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, []os.FileInfo) []string
}

CopyTreeOptions ...

type Event

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

Event ...

func (*Event) C

func (me *Event) C() <-chan struct{}

C Returns a chan that is closed when the event is true.

func (*Event) Clear

func (me *Event) Clear()

Clear ... TODO: Merge into Set.

func (*Event) IsSet

func (me *Event) IsSet() bool

IsSet ... TODO: Change to Get.

func (*Event) LockedChan

func (me *Event) LockedChan(lock sync.Locker) <-chan struct{}

LockedChan ...

func (*Event) Set

func (me *Event) Set() (first bool)

Set the event to true/on.

func (*Event) SetBool

func (me *Event) SetBool(b bool)

SetBool ... TODO: Merge into Set.

func (*Event) Wait

func (me *Event) Wait()

Wait ...

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 ...

Jump to

Keyboard shortcuts

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