utils

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: MIT Imports: 15 Imported by: 0

README

goutils:

history

2017/04/09

GetRequestIP(r *http.Request)     
//get request from http.Request

201&/07/26

GetHostIP() (string,error)   
//return host self ip

Documentation

Index

Constants

View Source
const (
	DEFAULT_UNZIP_LIMIT = 64 * 1024 * 1024 * 1024
)

Variables

View Source
var (
	ErrUserQuit = errors.New("quit by user")
)

Functions

func ApplicationName

func ApplicationName() string

ApplicationName: return `this program`'s basename, if run in windows, returned string auto removed ".exe"

func CleanFileName

func CleanFileName(parent, name string) string

func DoListDir

func DoListDir(dirPth string, suffix string, f func(fileName string) error) error

获取指定目录下的所有文件,不进入下一级目录搜索,可以匹配后缀过滤。

func DoListDirEx

func DoListDirEx(dirPth string, suffix string, f func(fullpath string, fileName string) error) error

获取指定目录下的所有文件,不进入下一级目录搜索,可以匹配后缀过滤。

func DoWalkDir

func DoWalkDir(dirPth, suffix string, f func(fileName string, isdir bool) error) error

获取指定目录及所有子目录下的所有文件,可以匹配后缀过滤。

func GetExternalIP

func GetExternalIP() (string, error)

返回公网出口IP

func GetHostIP

func GetHostIP() (string, error)

返回主机HOST IP

func GetInternalIP

func GetInternalIP() (string, error)

返回主机内部IP(顺序第一个)

func GetInternalIPByDevName

func GetInternalIPByDevName(dev string) ([]string, error)

根据网卡设备名称返回内部IP

func GetLocalConnectIP

func GetLocalConnectIP(proto string, addr string) (string, error)

在主机拥有多个IP地址时,返回能够连通对端网络的自身主机IP

func GetRequestIP

func GetRequestIP(r *http.Request) string

返回HTTP请求IP,优先级(X-Real-IP>X-Forwarded-For>Proxy-Client-IP>WL-Proxy-Client-IP")

func GetUploadFileSize

func GetUploadFileSize(upfile multipart.File) (int64, error)

返回HTTP upload文件的大小

func Index

func Index(s, substr string, start int) int

func Inet_aton

func Inet_aton(ipnr net.IP) int64

func Inet_ntoa

func Inet_ntoa(ipnr int64) net.IP

func IsPublicIP

func IsPublicIP(IP net.IP) bool

func ListDir

func ListDir(dirPth string, suffix string, ch chan<- string) error

获取指定目录下的所有文件,不进入下一级目录搜索,可以匹配后缀过滤。

func MultiCopy

func MultiCopy(src io.Reader, writers ...io.Writer) (written int64, err error)

MultiCopy like io.MultiWriters only need an interface implement io.Write([]byte)

func PathExists

func PathExists(filename string) bool

func PathExists2

func PathExists2(filename string) (bool, error)

func ScanZip

func ScanZip(archive, tmpDir string, sizeLimit uint64, scanCall func(filename string) error) error

func ScanZipM

func ScanZipM(archive string, sizeLimit uint64, scanCall func(f *zip.File) error) error

func TempFileName

func TempFileName(dir, prefix string) (string, error)

TempFileName: new a temp filename in `dir` with `prefix`

func Unzip

func Unzip(src, dest string) error

func UnzipSafe

func UnzipSafe(archive, target string, sizeLimit uint64) error

func WalkDir

func WalkDir(dirPth, suffix string, ch chan<- string) error

获取指定目录及所有子目录下的所有文件,可以匹配后缀过滤。

func WildcardCmp

func WildcardCmp(txt, pattern string) bool

wirdcard match, see https://en.wikipedia.org/wiki/Wild_card

func ZipSize

func ZipSize(zipR *zip.ReadCloser) uint64

Types

type Size

type Size interface {
	Size() int64
}

获取文件大小的接口

type Stat

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

获取文件信息的接口

type VersionInt

type VersionInt struct {
	Major    int
	Minor    int
	Revision int
	Build    string
}

func NewVersionInt

func NewVersionInt(verstr string, sepStr string) VersionInt

func (*VersionInt) Compatible

func (v *VersionInt) Compatible(nv *VersionInt) bool

func (*VersionInt) Equal

func (v *VersionInt) Equal(nv *VersionInt) bool

func (*VersionInt) GreatThan

func (v *VersionInt) GreatThan(nv *VersionInt) bool

func (*VersionInt) LessThan

func (v *VersionInt) LessThan(nv *VersionInt) bool

Jump to

Keyboard shortcuts

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