egb

package module
v0.0.0-...-7a6b824 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2017 License: MIT Imports: 34 Imported by: 0

README

egb Build Status

yeeyun golang lib

Documentation

Index

Constants

View Source
const LowerAlphaSeed = "abcdefghijklmnopqrstuvwxyz"
View Source
const NumSeed = "0123456789"
View Source
const Seed = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
View Source
const UpperAlphaSeed = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

Variables

View Source
var UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1541.0 Safari/537.36"

Functions

func AESDecrypt

func AESDecrypt(key, text []byte) ([]byte, error)

AESDecrypt decrypts text and given key with AES.

func AESEncrypt

func AESEncrypt(key, text []byte) ([]byte, error)

AESEncrypt encrypts text and given key with AES.

func BytesReader

func BytesReader(data interface{}) io.Reader

BytesReader convert interface{} to io.Reader

func CheckErr

func CheckErr(err error) string

func Download

func Download(urlStr, filename string) (size int64, err error)

下载文件

func ExecCmd

func ExecCmd(cmdName string, args ...string) (string, string, error)

ExecCmd executes system command and return stdout, stderr in string type, along with possible error.

func ExecCmdBytes

func ExecCmdBytes(cmdName string, args ...string) ([]byte, []byte, error)

ExecCmdBytes executes system command and return stdout, stderr in bytes type, along with possible error.

func ExecCmdDir

func ExecCmdDir(dir, cmdName string, args ...string) (string, string, error)

ExecCmdDir executes system command in given directory and return stdout, stderr in string type, along with possible error.

func ExecCmdDirBytes

func ExecCmdDirBytes(dir, cmdName string, args ...string) ([]byte, []byte, error)

ExecCmdDirBytes executes system command in given directory and return stdout, stderr in bytes type, along with possible error.

func FileAppendBytes

func FileAppendBytes(filename string, data []byte) error

FileAppendBytes append bytes to the given file.

func FileAppendString

func FileAppendString(filename string, data string) error

FileAppendString append string to the given file.

func FileBufferedReader

func FileBufferedReader(filenameOrURL string) (io.Reader, error)

FileBufferedReader return io.Reader or error by the given file url.

func FileCopy

func FileCopy(source string, dest string) (err error)

FileCopy copies file source to destination dest.

func FileCopyDir

func FileCopyDir(source string, dest string) (err error)

FileCopyDir recursively copies a directory tree, attempting to preserve permissions. Source directory must exist, destination directory must *not* exist.

func FileExists

func FileExists(filename string) bool

FileExists return true if the given file exist.

func FileFind

func FileFind(searchDirs []string, filenames ...string) (filePath string, found bool)

FileFind find given file int the given dirs and return the result.

func FileGetBytes

func FileGetBytes(filenameOrURL string, timeout ...time.Duration) ([]byte, error)

FileGetBytes return []byte or error by the given url and timeout.

func FileGetExt

func FileGetExt(filename string) string

FileGetExt return the ext of filename.

func FileGetPrefix

func FileGetPrefix(filename string) string

FileGetPrefix return the prefix of filename.

func FileGetString

func FileGetString(filenameOrURL string, timeout ...time.Duration) (string, error)

FileGetString get file string content by given filename or url and timeout.

func FileIsDir

func FileIsDir(dirname string) bool

FileIsDir return true if the given filename is a dir.

func FileSetBytes

func FileSetBytes(filename string, data []byte) error

FileSetBytes set bytes to the given file.

func FileSetString

func FileSetString(filename string, data string) error

FileSetString set string to the given file.

func FileSize

func FileSize(filename string) int64

FileSize returns the size of a file or zero in case of an error.

func FileTimeModified

func FileTimeModified(filename string) time.Time

FileTimeModified returns the modified time of a file, or the zero time value in case of an error.

func GetImageInfo

func GetImageInfo(inputFilePath string) (int, int, error)

GetImageInfo 获取图片的宽高信息 @params inputFilePath @return (int,int,error)

func HttpCall

func HttpCall(client *http.Client, method, url string, header http.Header, body io.Reader) (io.ReadCloser, error)

HttpCall makes HTTP method call.

func HttpGet

func HttpGet(client *http.Client, url string, header http.Header) (io.ReadCloser, error)

HttpGet gets the specified resource. ErrNotFound is returned if the server responds with status 404. eg: rc, err := HttpGet(&http.Client{}, "http://example.com", nil) p, err := ioutil.ReadAll(rc) s := string(p)

func HttpGetBytes

func HttpGetBytes(client *http.Client, url string, header http.Header) ([]byte, error)

HttpGetBytes gets the specified resource. ErrNotFound is returned if the server responds with status 404.

func HttpGetToFile

func HttpGetToFile(client *http.Client, url string, header http.Header, fileName string) error

HttpGetToFile gets the specified resource and writes to file. ErrNotFound is returned if the server responds with status 404.

func HttpPost

func HttpPost(client *http.Client, url string, header http.Header, body []byte) (io.ReadCloser, error)

HttpPost posts the specified resource. ErrNotFound is returned if the server responds with status 404. var params = url.Values{} param.Add("userName", user) param.Add("pwd", pwd) data := param.Encode() rc, err := HttpGet(&http.Client{}, "http://example.com", nil,[]byte(data)) p, err := ioutil.ReadAll(rc) s := string(p)

func ImageBase64ToFile

func ImageBase64ToFile(datasource, filename string) error

ImageBase64ToFile convert base64 string to a image file.

func ImageBase64ToImg

func ImageBase64ToImg(datasource string) (image.Image, error)

ImageBase64ToImg convert base64 string to image.Image.

func ImageFileToBase64

func ImageFileToBase64(filename string) string

ImageFileToBase64 图片文件转base64

func ImageImgToBase64

func ImageImgToBase64(image image.Image) string

ImageImgToBase64 convert image.Image to base64 string.

func ImageImgToFile

func ImageImgToFile(image image.Image, filename string) error

ImageImgToFile convert image to file.

func ListDir

func ListDir(dir string) ([]string, error)

ListDir return all the names from the directory in a single slice.

func ListDirDirectories

func ListDirDirectories(dir string) ([]string, error)

//ListDirDirectories return all the directory names from the directory.

func ListDirFiles

func ListDirFiles(dir string) ([]string, error)

ListDirFiles return all the file names from the directory.

func LoadImage

func LoadImage(path string) (img image.Image, err error)

LoadImage decodes an image from a file.

func NewUpload

func NewUpload(rootpath string) *upload

NewUpload 构造方法 必须使用这个方法初始化一个Upload对象

func ProcessImage

func ProcessImage(inputFilePath string, processConfig ImageProcessor) error

ProcessImage 剪裁图片 传入图片的存储路径 name 以及剪裁参数 返回图片的name

func RandInt64Between

func RandInt64Between(min, max int64) int64

RandIntBetween return random int64 between two given int.

func RandIntBetween

func RandIntBetween(min, max int) int

RandIntBetween return random int between two given int.

func RandNum

func RandNum(length int) string

RandNum return the rand num string by given length.

func RandNumber

func RandNumber(start int, end int, count int) []int

RandNumber return no-repeat number by given start end and count[min,max).

func RandString

func RandString(length int) string

RandString return the rand string by given length.

func RegexpIsEmailAddress

func RegexpIsEmailAddress(email string) bool

RegexpIsEmailAddress return true if the given string is a email address.

func RegexpIsPhoneNumber

func RegexpIsPhoneNumber(mobileNum string) bool

RegexpIsPhoneNumber return true if given string is a phone number.

func RegexpIsStrongPassword

func RegexpIsStrongPassword(pwd string) bool

RegexpIsStrongPassword return true if the given string is a strong pwd(6位以上数字和字母的组合).

func RegexpIsUrl

func RegexpIsUrl(url string) bool

RegexpIsUrl return true if the given string is a true url.

func ResizeImage

func ResizeImage(inputImagePath string, width, height uint, outputFileName string) error

ResizeImage 图片缩放 @params inputImagePath width height outputFileName @return error

func RotateImage

func RotateImage(inputImagePath, outputImagePath string, angle float64) error

RotateImage 旋转图片 参数为角度(顺时针) @params inputImagePath outputImagePath angle @return error

func SaveImage

func SaveImage(path string, img image.Image) error

SaveImage 将image.image保存进某个path 以png格式 @params path img @return error

func SetConfig

func SetConfig(filepath string) *config

Create an empty configuration file

func SliceAppendStr

func SliceAppendStr(strs []string, str string) []string

SliceAppendStr appends string to slice with no duplicates.

func SliceCompareInt

func SliceCompareInt(s1, s2 []int) bool

SliceCompareStr compares two 'int' type slices. It returns true if elements and order are both the same.

func SliceCompareIntIgnoreOrder

func SliceCompareIntIgnoreOrder(s1, s2 []int) bool

SliceCompareStrIgnoreOrder compares two 'int' type slices. It returns true if elements are the same, and ignores the order.

func SliceCompareStr

func SliceCompareStr(s1, s2 []string) bool

SliceCompareStr compares two 'string' type slices. It returns true if elements and order are both the same.

func SliceCompareStrIgnoreOrder

func SliceCompareStrIgnoreOrder(s1, s2 []string) bool

SliceCompareStrIgnoreOrder compares two 'string' type slices. It returns true if elements are the same, and ignores the order.

func StringAddURLParam

func StringAddURLParam(url, name, value string) string

StringAddURLParam add url param for given url.

func StringBase64Decode

func StringBase64Decode(data string) (string, error)

StringBase64Decode returns the string represented by the base64 string data. TODO test func

func StringBase64Encode

func StringBase64Encode(data string) string

StringBase64Encode returns the base64 encoding of data. TODO test func

func StringFilter

func StringFilter(f func(string) bool, data []string) []string

StringFilter filter out all strings where the function does not return true.

func StringFromFloat64

func StringFromFloat64(f float64) string

StringFromFloat64 convert float64 to string.

func StringFromInt

func StringFromInt(i int) string

StringFromInt convert int to string.

func StringFromInt64

func StringFromInt64(i int64) string

StringFromInt64 convert int64 to string.

func StringListContains

func StringListContains(list []string, str string) bool

StringListContains judge if the slice of string contains the given string element.

func StringListContainsCaseInsensitive

func StringListContainsCaseInsensitive(list []string, str string) bool

StringListContainsCaseInsensitive judge if the slice of string contains the given string element case-insensitive.

func StringMD5Hex

func StringMD5Hex(data string) string

StringMD5Hex returns the hex encoded MD5 hash of data.

func StringMapFunc

func StringMapFunc(f func(string) string, data []string) []string

StringMapFunc execute a function on each element of the slice of string.

func StringMarshalJSON

func StringMarshalJSON(data interface{}) string

StringMarshalJSON marshals data to an json string.

func StringReplaceHTMLTags

func StringReplaceHTMLTags(text, replacement string) (plainText string)

StringReplaceHTMLTags replaces HTML/XML tags from text with replacement.

func StringSHA1Hex

func StringSHA1Hex(data string) string

StringMD5Hex returns the hex encoded SHA1 hash of data.

func StringSHA256Hex

func StringSHA256Hex(data string) string

StringMD5Hex returns the hex encoded SHA256 hash of data.

func StringStripHTMLTags

func StringStripHTMLTags(text string) (plainText string)

StringStripHTMLTags strips HTML/XML tags from text.

func StringSubStr

func StringSubStr(s string, start, length int) string

StringSubStr returns the substr from start to length.

func StringToBool

func StringToBool(s string) bool

StringToInt convert string to bool. It accepts 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False.

func StringToFloat64

func StringToFloat64(s string) float64

StringToInt convert string to float64.

func StringToInt

func StringToInt(str string) int

StringToInt convert string to int.

func StringToInt64

func StringToInt64(s string) int64

StringToInt convert string to int64.

func StringToIntArray

func StringToIntArray(str string) ([]int, error)

StringToIntArray convert string to a int array eg: "1,2,3" => [1,2,3]

func ThumbImage

func ThumbImage(inputFileName string, maxWidth, maxHeight uint, outputFileName string) error

ImageThumbnail 生成缩略图 最大宽高,不会改变图片的比例 @params inputFile maxWidth maxHeight outputFile @return error

func TimeDay

func TimeDay() string

TimeDay return now day string.

func TimeDayToUnix

func TimeDayToUnix(daytime string) string

TimeDayToUnix return unix time string by given format-time.

func TimeFromUnix

func TimeFromUnix(unix string) string

TimeFromUnix return normal format time from unix time string.

func TimeFromUnixNano

func TimeFromUnixNano(unix string) string

TimeFromUnixNano return normal format time from unix nano time string.

func TimeMonth

func TimeMonth() string

TimeMonth return now month string.

func TimeNowDate

func TimeNowDate() string

TimeNowDate return now date time string.

func TimeNowDateDay

func TimeNowDateDay() string

TimeNowDateDay return now date day time string.

func TimeNowUnix

func TimeNowUnix() string

TimeNowUnix return now unix time string.

func TimeNowUnixMs

func TimeNowUnixMs() string

TimeNowUnixMs return now unix ms time string.

func TimeNowUnixNano

func TimeNowUnixNano() string

TimeNowUnixNano return now unix nano time string.

func TimeSecondToUnix

func TimeSecondToUnix(stime string) string

TimeSecondToUnix return unix time string by given format-time.

func TimeWeekDay

func TimeWeekDay() string

TimeWeekDay return now week day string. eg:Friday

func TimeYear

func TimeYear() string

TimeYear return now year string.

func URLDecode

func URLDecode(str string) (string, error)

URLDecode return decode url string.

func URLEncode

func URLEncode(str string) string

URLEncode return encode url string.

Types

type FileCopyError

type FileCopyError struct {
	What string
}

A struct for returning file copy error messages

func (*FileCopyError) Error

func (e *FileCopyError) Error() string

type ImageProcessor

type ImageProcessor struct {
	//距离左边距离
	LeftPoint int
	//距离上边距离
	TopPoint int
	//裁剪后的宽
	Width int
	//剪裁后的高
	Height int
}

ImageProcessor 图片剪裁参数

type RequestWrapper

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

封装的http请求 请求客户端 Request Response error(如果有错误发生)

func Delete

func Delete(urlStr string) *RequestWrapper

func Get

func Get(urlStr string) *RequestWrapper

func NewRequest

func NewRequest(method, urlStr string) *RequestWrapper

func Post

func Post(urlStr string) *RequestWrapper

func Put

func Put(urlStr string) *RequestWrapper

func (*RequestWrapper) Exec

func (r *RequestWrapper) Exec() *RequestWrapper

执行http请求

func (*RequestWrapper) Json

func (r *RequestWrapper) Json(data string) *RequestWrapper

设置post请求的参数 body主体 `{"greeting":"hello world"}`

func (*RequestWrapper) Param

func (r *RequestWrapper) Param(key, value string) *RequestWrapper

添加url参数

func (*RequestWrapper) Pipe

func (r *RequestWrapper) Pipe(w io.Writer) (written int64, err error)

结果输出为io.Writer 返回length 以及error

func (*RequestWrapper) Query

func (r *RequestWrapper) Query(query string) *RequestWrapper

func (*RequestWrapper) Set

func (r *RequestWrapper) Set(key, value string) *RequestWrapper

设置header

func (*RequestWrapper) ToBytes

func (r *RequestWrapper) ToBytes() ([]byte, error)

结果输出为[]byte

func (*RequestWrapper) ToFile

func (r *RequestWrapper) ToFile(filename string) (size int64, err error)

结果输出到文件

func (*RequestWrapper) ToString

func (r *RequestWrapper) ToString() (string, error)

结果输出为string

func (*RequestWrapper) Use

func (r *RequestWrapper) Use(client *http.Client) *RequestWrapper

设置client

type Sizer

type Sizer interface {
	Size() int64
}

Sizer 获取文件大小

type Stat

type Stat interface {
	Stat() (os.FileInfo, error)
}

Stat 获取文件信息的接口

type UploadReturnInfo

type UploadReturnInfo struct {
	Err      error  //错误,如果存在,则上传失败
	URL      string //文件地址 rootpath-1(/static/xx/xx/xx) + filename + ext(直接用于显示用,即直接存储在数据库中的)
	Filename string //文件名 filename
	Ext      string //文件后缀 ext
}

UploadReturnInfo 执行上传后返回的信息

Directories

Path Synopsis
仿照:https://github.com/orcaman/concurrent-map的思路
仿照:https://github.com/orcaman/concurrent-map的思路

Jump to

Keyboard shortcuts

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