utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2019 License: MIT Imports: 20 Imported by: 3

Documentation

Index

Constants

View Source
const (
	B int64 = 1 << (10 * iota)
	KB
	MB
	GB
	TB
	PB
)

Variables

This section is empty.

Functions

func CleanPath

func CleanPath(p string) string

CleanPath is the URL version of path.Clean, it returns a canonical URL path for p, eliminating . and .. elements.

The following rules are applied iteratively until no further processing can be done:

  1. Replace multiple slashes with a single slash.
  2. Eliminate each . path name element (the current directory).
  3. Eliminate each inner .. path name element (the parent directory) along with the non-.. element that precedes it.
  4. Eliminate .. elements that begin a rooted path: that is, replace "/.." by "/" at the beginning of a path.

If the result of this process is an empty string, "/" is returned

func CopyDir

func CopyDir(src string, dst string) (err error)

func CopyFile

func CopyFile(src string, dst string) (n int64, err error)

func DecodeGob

func DecodeGob(data []byte, v interface{}) (err error)

func EncodeGob

func EncodeGob(v interface{}) (data []byte, err error)

func FileExt

func FileExt(filename string) (ext string)

func GetLocalIPs

func GetLocalIPs() (ips []string, err error)

func HashString

func HashString(input interface{}, hasher hash.Hash) string

func Ipv4ToLong

func Ipv4ToLong(ipStr string) uint32

func LongToIpv4

func LongToIpv4(ipLong uint32) string

func MustEncodeGob

func MustEncodeGob(v interface{}) []byte

func ParseBytes

func ParseBytes(s string) (int64, error)

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

todo: parse format '1d6h30m20s'

func ParseGobFile

func ParseGobFile(filename string, v interface{}) (err error)

func ParseJSONFile

func ParseJSONFile(filename string, v interface{}) (err error)

func ParseLines

func ParseLines(s string, keepEmptyLine bool) (lines []string)

func SaveGobFile

func SaveGobFile(filename string, v interface{}) (err error)

func SaveJSONFile

func SaveJSONFile(filename string, v interface{}) (err error)

func SaveJSONFileWithIndent

func SaveJSONFileWithIndent(filename string, v interface{}, prefix string, indent string) (err error)

func SplitByFirstByte

func SplitByFirstByte(s string, c byte) (string, string)

func SplitByLastByte

func SplitByLastByte(s string, c byte) (string, string)

func ToNumber

func ToNumber(v interface{}) (f float64, ok bool)

func WaitExit

func WaitExit(callback func(os.Signal) bool, extraSignals ...os.Signal)

Types

This section is empty.

Jump to

Keyboard shortcuts

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