tools

package
v0.0.0-...-c7a3bb2 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: MIT Imports: 29 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 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 GetGoEol

func GetGoEol() string

func GetHttpData

func GetHttpData(url string) (string, error)

func GetPublicIP

func GetPublicIP() (ip string, err 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 InitAutoMakeTLSConfig

func InitAutoMakeTLSConfig() *tls.Config

func InitAutoMakeTLSConfigWithArgs

func InitAutoMakeTLSConfigWithArgs(cert, key string) *tls.Config

func Int2HexStr

func Int2HexStr(num int) (hex string)

Int2HexStr converts decimal number to hex format string.

func IsCodeRe

func IsCodeRe(b string) bool

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 IsEmailRe

func IsEmailRe(b string) bool

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 IsIpv4Re

func IsIpv4Re(b string) bool

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 IsUrlRe

func IsUrlRe(b string) bool

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 ReadFileByte

func ReadFileByte(file string) ([]byte, error)

func RemoveDuplicatesAndEmpty

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

func SizeFormat

func SizeFormat(size float64) string

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 ToSize

func ToSize(s int64) 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 Wrap

func Wrap(sl []byte) []byte

Wrap a byte slice paragraph for use in SMTP header

func WriteFile

func WriteFile(file string, content string) error

Types

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)

Directories

Path Synopsis
Package cron implements a cron spec parser and job runner.
Package cron implements a cron spec parser and job runner.
Package paginater is a helper module for custom pagination calculation.
Package paginater is a helper module for custom pagination calculation.
Modified UTF-7 encoding defined in RFC 3501 section 5.1.3
Modified UTF-7 encoding defined in RFC 3501 section 5.1.3

Jump to

Keyboard shortcuts

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