utils

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2019 License: MIT Imports: 36 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes2String

func Bytes2String(u []byte) string

func BytesToStringUnsafe

func BytesToStringUnsafe(b []byte) string

BytesToStringUnsafe converts a byte slice to a string. It's fasthttpgx, but not safe. Use it only if you know what you're doing.

func CPUProf

func CPUProf() func()

CPUProf runs the profiler and returns a function you need to defer

func Concat

func Concat(a string, b ...string) string

Concat some strings

func Decodebig5

func Decodebig5(s []byte) ([]byte, error)

convert BIG5 to UTF-8

func Decodegbk

func Decodegbk(s []byte) ([]byte, error)

convert GBK to UTF-8

func Detect

func Detect(b []byte) (*chardet.Result, error)

func Encodebig5

func Encodebig5(s []byte) ([]byte, error)

convert UTF-8 to BIG5

func First

func First(args ...interface{}) interface{}

First returns first argument of a function return use it like

myutils.First(ab())

func GbkToUtf8

func GbkToUtf8(s []byte) ([]byte, error)

func GetCurrentExecDir

func GetCurrentExecDir() (dir string, err error)

func GetCurrentPath

func GetCurrentPath() (string, error)

func GetFileSize

func GetFileSize(fullFilename string) int64

func GetOutboundIP

func GetOutboundIP() (net.IP, error)

Get preferred outbound ip of this machine

func Last

func Last(args ...interface{}) interface{}

Last returns first argument of a function return use it like

myutils.Last(ab())

func LogFatalError

func LogFatalError(err error)

LogFatalError it's a snippet for

if err != nil {
    log.Fatalf("Error: %s", err)
}

func Md5CheckSum

func Md5CheckSum(filePath string) (result string, err error)

func MgoUuid

func MgoUuid() string

*

func Uuid4() uuid.UUID {
	return uuid.NewV4()
}

func NewGuid

func NewGuid() string

func Pick

func Pick(index int, args ...interface{}) interface{}

Pick returns picked argument of a function return use it like

myutils.Pick(1, ab())

func RequiredStrFatal

func RequiredStrFatal(name, str string)

RequiredStrFatal it's a snippet for

if str == "" {
    log.Fatalf("Error: %s is empty", name)
}

func Slice

func Slice(args ...interface{}) []interface{}

Slice returns arguments of a function return as a slice use it like

myutils.Slice(ab())[1]

func StrBuilder

func StrBuilder(args ...string) string

func StrCrop

func StrCrop(str string, length int) string

StrCrop crops a string like you want in blog previews

func StringToBytesUnsafe

func StringToBytesUnsafe(s string) []byte

StringToBytesUnsafe converts a string to a byte slice. It's fasthttpgx, but not safe. Use it only if you know what you're doing.

func SubString

func SubString(str string, begin, length int) (substr string)

func Trans

func Trans(input []byte, log zerolog.Logger) (output []byte, err error)

Trans translate code to simplechinese

func Utf8ToGbk

func Utf8ToGbk(s []byte) ([]byte, error)

func Uuid4

func Uuid4() string

func Uuid4Base58

func Uuid4Base58() string

Types

type Guid

type Guid struct {
	Uuid uuid.UUID
}

func (Guid) String

func (u Guid) String() string

type RWatcher

type RWatcher struct {
	Events chan fsnotify.Event
	Errors chan error
	// contains filtered or unexported fields
}

RWatcher wraps fsnotify.Watcher. When fsnotify adds recursive watches, you should be able to switch your code to use fsnotify.Watcher

func NewWatcher

func NewWatcher() (*RWatcher, error)

NewWatcher establishes a new watcher with the underlying OS and begins waiting for events.

func (*RWatcher) Add

func (m *RWatcher) Add(name string) error

Add starts watching the named file or directory (non-recursively).

func (*RWatcher) AddRecursive

func (m *RWatcher) AddRecursive(name string) error

AddRecursive starts watching the named directory and all sub-directories.

func (*RWatcher) Close

func (m *RWatcher) Close() error

Close removes all watches and closes the events channel.

func (*RWatcher) Remove

func (m *RWatcher) Remove(name string) error

Remove stops watching the the named file or directory (non-recursively).

func (*RWatcher) RemoveRecursive

func (m *RWatcher) RemoveRecursive(name string) error

RemoveRecursive stops watching the named directory and all sub-directories.

type SyncPrinter

type SyncPrinter struct {
	Queue chan string
	Close chan bool
}

SyncPrinter is a thread-safe printer. It will output given queue without

func NewSyncPrinter

func NewSyncPrinter() (*SyncPrinter, error)

NewSyncPrinter initialize a new SyncPrinter

func (*SyncPrinter) Run

func (printer *SyncPrinter) Run()

Run a SyncPrinter instance

Jump to

Keyboard shortcuts

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