utils

package module
v0.0.0-...-fc20b2c Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2017 License: Apache-2.0 Imports: 24 Imported by: 0

README

util

go工具包

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileExists

func FileExists(name string) bool

FileExists reports whether the named file or directory exists.

func GetFuncName

func GetFuncName(i interface{}) string

GetFuncName get function name

func GrepFile

func GrepFile(patten string, filename string) (lines []string, err error)

GrepFile like command grep -E for example: GrepFile(`^hello`, "hello.txt") \n is striped while read

func InSlice

func InSlice(v string, sl []string) bool

InSlice checks given string in string slice or not.

func InSliceIface

func InSliceIface(v interface{}, sl []interface{}) bool

InSliceIface checks given interface in interface slice.

func RandomCreateBytes

func RandomCreateBytes(n int, alphabets ...byte) []byte

RandomCreateBytes generate random []byte by specify chars.

func SearchFile

func SearchFile(filename string, paths ...string) (fullpath string, err error)

SearchFile Search a file in paths. this is often used in search config file in /etc ~/

func SelfDir

func SelfDir() string

SelfDir gets compiled executable file directory

func SelfPath

func SelfPath() string

SelfPath gets compiled executable file absolute path

func SliceChunk

func SliceChunk(slice []interface{}, size int) (chunkslice [][]interface{})

SliceChunk separates one slice to some sized slice.

func SliceDiff

func SliceDiff(slice1, slice2 []interface{}) (diffslice []interface{})

SliceDiff returns diff slice of slice1 - slice2.

func SliceFilter

func SliceFilter(slice []interface{}, a filtertype) (ftslice []interface{})

SliceFilter generates a new slice after filter function.

func SliceIntersect

func SliceIntersect(slice1, slice2 []interface{}) (diffslice []interface{})

SliceIntersect returns slice that are present in all the slice1 and slice2.

func SliceMerge

func SliceMerge(slice1, slice2 []interface{}) (c []interface{})

SliceMerge merges interface slices to one slice.

func SlicePad

func SlicePad(slice []interface{}, size int, val interface{}) []interface{}

SlicePad prepends size number of val into slice.

func SliceRand

func SliceRand(a []interface{}) (b interface{})

SliceRand returns random one from slice.

func SliceRandList

func SliceRandList(min, max int) []int

SliceRandList generate an int slice from min to max.

func SliceRange

func SliceRange(start, end, step int64) (intslice []int64)

SliceRange generates a new slice from begin to end with step duration of int64 number.

func SliceReduce

func SliceReduce(slice []interface{}, a reducetype) (dslice []interface{})

SliceReduce generates a new slice after parsing every value by reduce function

func SliceShuffle

func SliceShuffle(slice []interface{}) []interface{}

SliceShuffle shuffles a slice.

func SliceSum

func SliceSum(intslice []int64) (sum int64)

SliceSum sums all values in int64 slice.

func SliceUnique

func SliceUnique(slice []interface{}) (uniqueslice []interface{})

SliceUnique cleans repeated values in slice.

func Trycatch

func Trycatch(try func(), catch func(e interface{}))

Types

type Attachment

type Attachment struct {
	Filename string
	Header   textproto.MIMEHeader
	Content  []byte
}

Attachment is a struct representing an email attachment. Based on the mime/multipart.FileHeader struct, Attachment contains the name, MIMEHeader, and content of the attachment in question

type Email

type Email struct {
	Auth        smtp.Auth
	Identity    string `json:"identity"`
	Username    string `json:"username"`
	Password    string `json:"password"`
	Host        string `json:"host"`
	Port        int    `json:"port"`
	From        string `json:"from"`
	To          []string
	Bcc         []string
	Cc          []string
	Subject     string
	Text        string // Plaintext message (optional)
	HTML        string // Html message (optional)
	Headers     textproto.MIMEHeader
	Attachments []*Attachment
	ReadReceipt []string
}

Email is the type used for email messages

func NewEMail

func NewEMail(config string) *Email

NewEMail create new Email struct with config json. config json is followed from Email struct fields.

func (*Email) Attach

func (e *Email) Attach(r io.Reader, filename string, args ...string) (a *Attachment, err error)

Attach is used to attach content from an io.Reader to the email. Parameters include an io.Reader, the desired filename for the attachment, and the Content-Type.

func (*Email) AttachFile

func (e *Email) AttachFile(args ...string) (a *Attachment, err error)

AttachFile Add attach file to the send mail

func (*Email) Bytes

func (e *Email) Bytes() ([]byte, error)

Bytes Make all send information to byte

func (*Email) Send

func (e *Email) Send() error

Send will send out the mail

type SafeMap

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

SafeMap is a map with lock

func NewSafeMap

func NewSafeMap() *SafeMap

NewSafeMap return new safemap

func (*SafeMap) Check

func (m *SafeMap) Check(k interface{}) bool

Check Returns true if k is exist in the map.

func (*SafeMap) Delete

func (m *SafeMap) Delete(k interface{})

Delete the given key and value.

func (*SafeMap) Get

func (m *SafeMap) Get(k interface{}) interface{}

Get from maps return the k's value

func (*SafeMap) Items

func (m *SafeMap) Items() map[interface{}]interface{}

Items returns all items in safemap.

func (*SafeMap) Set

func (m *SafeMap) Set(k interface{}, v interface{}) bool

Set Maps the given key and value. Returns false if the key is already in the map and changes nothing.

type WaitGroupWrapper

type WaitGroupWrapper struct {
	sync.WaitGroup
}

func (*WaitGroupWrapper) Wrap

func (w *WaitGroupWrapper) Wrap(cb func())

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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