tools

package
v0.0.0-...-a52fffe Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Minute = 60
	Hour   = 60 * Minute
	Day    = 24 * Hour
	Week   = 7 * Day
	Month  = 30 * Day
	Year   = 12 * Month
)

Seconds-based time units

Variables

This section is empty.

Functions

func Base64decode

func Base64decode(in string) (string, error)

func Base64encode

func Base64encode(in string) string

func BytesToString

func BytesToString(b []byte) string

Byte to string, only read-only

func CheckStandardMail

func CheckStandardMail(src string) bool

func CheckStringIsExist

func CheckStringIsExist(source string, check []string) bool

func ConvertToString

func ConvertToString(src string, srcCode string, tagCode string) string

func CurrentUsername

func CurrentUsername() string

CurrentUsername returns the username of the current user.

func FileSize

func FileSize(s int64) string

FileSize calculates the file size and generate user-friendly string.

func FilterAddressBody

func FilterAddressBody(src string) string

func GetHttpData

func GetHttpData(url string) (string, error)

func GetRealMail

func GetRealMail(src string) string

func HexStr2int

func HexStr2int(hexStr string) (int, error)

HexStr2int converts hex format string to decimal number.

func Int2HexStr

func Int2HexStr(num int) (hex string)

Int2HexStr converts decimal number to hex format string.

func IsDir

func IsDir(dir string) bool

IsDir returns true if given path is a directory, and returns false when it's a file or does not exist.

func IsExist

func IsExist(path string) bool

IsExist returns true if a file or directory exists.

func IsFile

func IsFile(path string) bool

IsFile returns true if given path exists as a file (i.e. not a directory).

func IsMaliciousPath

func IsMaliciousPath(path string) bool

IsMaliciousPath returns true if given path is an absolute path or contains malicious content which has potential to traverse upper level directories.

func IsNumeric

func IsNumeric(val interface{}) bool

is_numeric()

func IsSameSiteURLPath

func IsSameSiteURLPath(url string) bool

IsSameSiteURLPath returns true if the URL path belongs to the same site, false otherwise. False: //url, http://url, /\url True: /url

func Md5

func Md5(s string) string

func Md5Byte

func Md5Byte(buf []byte) string

func PathExists

func PathExists(path string) (bool, error)

func PowInt

func PowInt(x int, y int) int

PowInt is int type of math.Pow function.

func RandString

func RandString(len int) string

func ReadFile

func ReadFile(file string) (string, error)

func RemoveDuplicatesAndEmpty

func RemoveDuplicatesAndEmpty(a []string) (ret []string)

func SizeFormat

func SizeFormat(size float64) string

func StringToBytes

func StringToBytes(str string) []byte

String to byte, only read-only

func TimeSincePro

func TimeSincePro(then time.Time) string

TimeSincePro calculates the time interval and generate full user-friendly string.

func ToEditorLang

func ToEditorLang(lang string) string

func ToSlice

func ToSlice(input string) ([]int64, error)

func ToSnakeCase

func ToSnakeCase(str string) string

ToSnakeCase can convert all upper case characters in a string to underscore format.

Some samples.

"FirstName"  => "first_name"
"HTTPServer" => "http_server"
"NoHTTPS"    => "no_https"
"GO_PATH"    => "go_path"
"GO PATH"    => "go_path"      // space is converted to underscore.
"GO-PATH"    => "go_path"      // hyphen is converted to underscore.

From https://github.com/huandu/xstrings

func ToStr

func ToStr(value interface{}, args ...int) (s string)

Convert any type to string.

func WriteFile

func WriteFile(file string, content string) error

Types

type Pager

type Pager struct {
	Page     int
	Totalnum int
	Pagesize int
	// contains filtered or unexported fields
}

func NewPager

func NewPager(page, totalnum, pagesize int, url string, nopath ...bool) *Pager

func (*Pager) ToString

func (this *Pager) ToString() string

type StrTo

type StrTo string

Convert string to specify type.

func (StrTo) Exist

func (f StrTo) Exist() bool

func (StrTo) Float64

func (f StrTo) Float64() (float64, error)

func (StrTo) Int

func (f StrTo) Int() (int, error)

func (StrTo) Int64

func (f StrTo) Int64() (int64, error)

func (StrTo) MustFloat64

func (f StrTo) MustFloat64() float64

func (StrTo) MustInt

func (f StrTo) MustInt() int

func (StrTo) MustInt64

func (f StrTo) MustInt64() int64

func (StrTo) MustUint8

func (f StrTo) MustUint8() uint8

func (StrTo) String

func (f StrTo) String() string

func (StrTo) Uint8

func (f StrTo) Uint8() (uint8, error)

Jump to

Keyboard shortcuts

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