stutil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: MIT Imports: 30 Imported by: 0

README

stutil is a simple tool box.

Documentation

Overview

pprof.go

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultContentType  = "application/x-www-form-urlencoded; charset=utf-8"
	HTTPFORMContentType = "application/x-www-form-urlencoded"
	HTTPJSONContentType = "application/json"
	HTTPXMLContentType  = "text/xml"
	HTTPFILEContentType = "multipart/form-data"
)

HTTP content type

View Source
var DefaultHeaders = map[string]string{
	"Connection": "keep-alive",
	"Accept":     "*/*",
	"User-Agent": "Chrome",
}

DefaultHeaders define default headers

Functions

func BytesToStringUnsafe

func BytesToStringUnsafe(b []byte) string

func DecodeFixed32

func DecodeFixed32(b []byte) (x uint32)

func DecodeRawBytes

func DecodeRawBytes(b []byte, alloc bool) (s []byte, alloc_len int)

func DecodeVarint

func DecodeVarint(b []byte) (x uint64, n int)

func EncodeFixed32

func EncodeFixed32(b []byte, x uint32)

func EncodeRawBytes

func EncodeRawBytes(b []byte, s []byte) int

func EncodeVarint

func EncodeVarint(b []byte, x uint64) int

func Exe added in v1.1.0

func Exe(cmddir, cmdstr string) string

func FileBase

func FileBase(path string) string

func FileCreate

func FileCreate(file string) (*os.File, error)

create file

func FileCreateAndWrite

func FileCreateAndWrite(path, content string) error

create a new file and write content

func FileCreateAndWriteWithBom

func FileCreateAndWriteWithBom(path, content string) error

func FileDelete

func FileDelete(path string) error

delete file

func FileDir

func FileDir(path string) (s string)

func FileFullPath

func FileFullPath(path string) (s string)

filepath

func FileIsExist

func FileIsExist(path string) bool

is exist

func FileIsHidden

func FileIsHidden(path string) bool

func FileIterateDir

func FileIterateDir(path, filter string, childrendir bool, callback func(file string) bool) error

FileIterateDir walk files,filter: txt|jpg

func FileIterateLine

func FileIterateLine(path string, callback func(num int, line string) bool) error

FileIterateLine read line whithout bom,num begin with 1

func FileLineNum

func FileLineNum(path string) (num int64)

file lines

func FileMD5

func FileMD5(path string) (string, error)

func FileMakeDir

func FileMakeDir(path string) error

make dir

func FileModTime

func FileModTime(path string) int64

file modified time

func FileMove added in v1.1.0

func FileMove(path string, to string) error

move file

func FileOnlyName

func FileOnlyName(path string) string

func FileOpenAppend

func FileOpenAppend(path string) (*os.File, error)

open appending file

func FileOpenWrite added in v1.1.0

func FileOpenWrite(path string) (*os.File, error)

open rw file

func FileReadAll

func FileReadAll(path string) ([]byte, error)

FileReadAll read file all content with bom

func FileReadDir

func FileReadDir(path string, noHidden bool, fileList map[string]os.FileInfo)

get all files and dirs

func FileReadLine added in v1.1.0

func FileReadLine(path string, line int) ([]string, error)

FileReadLine read special lines content

func FileRename

func FileRename(path string, to string) error

rename file

func FileSize

func FileSize(path string) int64

file size bytes

func FileStdinHasData

func FileStdinHasData() bool

func FileWriteAndAppend

func FileWriteAndAppend(path, content string) error

append string to file

func IntToString

func IntToString(i int64) string

func IsFile

func IsFile(path string) bool

is file

func LockWaitGroup

func LockWaitGroup(num int, f func(int) int) []int

func PProfSaveBlock

func PProfSaveBlock(p string) error

goroutine block

func PProfSaveMem

func PProfSaveMem(p string) error

func PProfStartCPU

func PProfStartCPU(p string) error

go tool pprof -svg cpu.pprof > cpu.svg

func PProfStopCPU

func PProfStopCPU(p string)

func RFloat32

func RFloat32(b []byte) float32

func RFloat64

func RFloat64(b []byte) float64

func RInt16

func RInt16(b []byte) int16

func RInt32

func RInt32(b []byte) int32

func RInt64

func RInt64(b []byte) int64

func RUint16

func RUint16(b []byte) (x uint16)

func RUint32

func RUint32(b []byte) (x uint32)

func RUint64

func RUint64(b []byte) (x uint64)

func RVarint

func RVarint(b []byte, x uint64) (int, error)

func ReflectMapValue

func ReflectMapValue(mp interface{}, key interface{}) interface{}

func ReflectSliceIndex

func ReflectSliceIndex(sl interface{}, index int) interface{}

func ReflectStructField

func ReflectStructField(st interface{}, filedname string) interface{}

func SSHExeCmd

func SSHExeCmd(client *ssh.Client, cmd string) (string, error)

func SSHFile

func SSHFile(user, keyFilePath, ip_port string) (*ssh.Client, error)

func SSHNew

func SSHNew(user, password, ip_port string) (*ssh.Client, error)

func SSHScp2Local

func SSHScp2Local(client *ssh.Client, remoteFile string, localFilePath string, process chan float32) (err error)

func SSHScp2Remote

func SSHScp2Remote(client *ssh.Client, localFile string, remotePathOrFile string, process chan float32) (err error)

func StringRegReplace

func StringRegReplace(reg, s, new string) (string, error)

func StringToBytesUnsafe

func StringToBytesUnsafe(s string) []byte

func StringToFloat

func StringToFloat(a string) float64

func StringToFloatList

func StringToFloatList(s, sep string) []float64

func StringToInt

func StringToInt(a string) int64

func StringToIntList

func StringToIntList(s, sep string) []int64

func StringToKVMap

func StringToKVMap(s, sep1, sep2 string) map[string]string

func StringToUint

func StringToUint(a string) uint64

func StringToUintList

func StringToUintList(s, sep string) []uint64

func SysDaemon

func SysDaemon() error

func SysLock

func SysLock()

func SysWaitSignal

func SysWaitSignal()

func Time2UnixM

func Time2UnixM(t time.Time) int64

func Time2UnixN

func Time2UnixN(t time.Time) int64

func Time2UnixS

func Time2UnixS(t time.Time) int64

func TimeFormat

func TimeFormat(t time.Time) string

func TimeFormatNeno

func TimeFormatNeno(t time.Time) string

func TimeFormatYMD

func TimeFormatYMD(t time.Time) string

func TimeNow

func TimeNow() time.Time

func TimeParse

func TimeParse(format, stime string) (time.Time, error)

func TimeParseUTC

func TimeParseUTC(format, stime string) (time.Time, error)

func TimeZeroClock

func TimeZeroClock(shift time.Duration) time.Time

func TimerReset

func TimerReset(t *time.Timer, d time.Duration)

func UintToString

func UintToString(i uint64) string

func Unix2Time

func Unix2Time(sec int64, nsec int64) time.Time

func UnsafeBytesToString added in v1.1.0

func UnsafeBytesToString(b []byte) string

func UnsafeStringToBytes added in v1.1.0

func UnsafeStringToBytes(s string) []byte

func WFloat32

func WFloat32(b []byte, x float32)

func WFloat64

func WFloat64(b []byte, x float64)

func WInt16

func WInt16(b []byte, x int16)

func WInt32

func WInt32(b []byte, x int32)

func WInt64

func WInt64(b []byte, x int64)

func WUint16

func WUint16(b []byte, x uint16)

func WUint32

func WUint32(b []byte, x uint32)

func WUint64

func WUint64(b []byte, x uint64)

func WVarint

func WVarint(b []byte) (x uint64, n int, e error)

Types

type HttpRequest

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

func (*HttpRequest) Cookie

func (req *HttpRequest) Cookie(cookie string) *HttpRequest

func (*HttpRequest) Do

func (req *HttpRequest) Do(method string, sUrl string) (resp *http.Response, body []byte, err error)

func (*HttpRequest) FormFile added in v1.1.0

func (req *HttpRequest) FormFile(params map[string]string, nameField, fileName string, file io.Reader) (*HttpRequest, error)

params post form的数据 nameField 请求地址上传文件对应field fileName 文件名 file 文件

func (*HttpRequest) FormJson

func (req *HttpRequest) FormJson(s string) *HttpRequest

func (*HttpRequest) FormParm

func (req *HttpRequest) FormParm(k, v string) *HttpRequest

func (*HttpRequest) Get

func (req *HttpRequest) Get(sUrl string) (resp *http.Response, body []byte, err error)

func (*HttpRequest) Header

func (req *HttpRequest) Header(key, val string) *HttpRequest

func (*HttpRequest) Post

func (req *HttpRequest) Post(sUrl string) (resp *http.Response, body []byte, err error)

func (*HttpRequest) Proxy

func (req *HttpRequest) Proxy(p string) *HttpRequest

func (*HttpRequest) SkipVerify

func (req *HttpRequest) SkipVerify() *HttpRequest

type Pair added in v1.2.0

type Pair struct {
	A interface{}
	B interface{}
}

func SortMap added in v1.2.0

func SortMap(mp interface{}, byKey, isDesc bool) []Pair

type STFile

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

func NewSTFile

func NewSTFile(path string) (*STFile, error)

func (*STFile) Close

func (f *STFile) Close()

func (*STFile) ReadLine

func (f *STFile) ReadLine() (string, int)

type TimeCost

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

func NewTimeCost

func NewTimeCost() *TimeCost

func (*TimeCost) Escape

func (c *TimeCost) Escape() int64

millisecond

Jump to

Keyboard shortcuts

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