utilkit

package
v0.0.0-...-ff6a228 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AirdbSuccess    uint = 20000
	AirdbFailed     uint = 20001
	AirdbAuthFailed uint = 20002
	AirdbUndefined  uint = 24999
	AirdbUnknown    uint = 25000
)

Airdb error codes for user.

View Source
const (
	FilePerm600 os.FileMode = 0o600 // For secret files.
	FilePerm644 os.FileMode = 0o644 // For normal files.
	FilePerm755 os.FileMode = 0o755 // For directory or execute files.
)
View Source
const (
	TimeFormatLong = "20060102150405"
	TimeFormatDay  = "2006-01-02"
)

Variables

View Source
var CodeMap = map[uint]string{
	AirdbSuccess:    "Success",
	AirdbFailed:     "Failed",
	AirdbAuthFailed: "Auth failed",
	AirdbUndefined:  "Undefined",
	AirdbUnknown:    "Uknown error",
}
View Source
var EnvMap = map[Env]string{
	EnvDev:  "dev",
	EnvTest: "test",
	EnvPro:  "pro",
	EnvLive: "live",
}

Functions

func BytesToString

func BytesToString(b []byte) string

b2s converts byte slice to a string without memory allocation. See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .

Note it may break if string and/or slice header will change in the future go versions.

func EnsureFileExists

func EnsureFileExists(path string)

func EnsureFolderExists

func EnsureFolderExists(folder string)

func Exists

func Exists(path string) bool

func ExtraTarFile

func ExtraTarFile(r io.Reader)

func FormCode

func FormCode(code uint) string

func FromEnv

func FromEnv(env Env) string

func GetEnvList

func GetEnvList() (envList []string)

func GetMd5Sum

func GetMd5Sum(f io.Reader) string

func GetNowLong

func GetNowLong() string

func GetTimeRFC

func GetTimeRFC(timestamp int64) string

func GetYearMonthDay

func GetYearMonthDay() string

func IOWriteFile

func IOWriteFile(r io.Reader, filePath string) error

func Intersection

func Intersection(slice1 []string, slice2 []string) []string

func IsLiveEnv

func IsLiveEnv(sEnv string) bool

func LastString

func LastString(ss []string) string

func LastStringWithSplit

func LastStringWithSplit(str, delimiter string) string

func RandString

func RandString(n int) string

func ReadFile

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

func Reverse

func Reverse(slice []string)

Reverse string slice [site user info 0] -> [0 info user site].

func StringToBytes

func StringToBytes(s string) (b []byte)

s2b converts string to a byte slice without memory allocation.

Note it may break if string and/or slice header will change in the future go versions.

func StringsRemove

func StringsRemove(slice []string, str string) []string

StringsRemove an value form an string slice.

func StringsToInts

func StringsToInts(slice []string) (ints []int, err error)

StringsToInts string slice to int slice.

func TemplateGenerateFileFromReader

func TemplateGenerateFileFromReader(reader io.Reader, dstPath string, data interface{}) error

func TemplateGenerateString

func TemplateGenerateString(str string, data interface{}) (string, error)

func ToCode

func ToCode(sCode string) uint

func ToSet

func ToSet(items []string) (ret []string)

func TrimStrings

func TrimStrings(slice []string, cutSet ...string) (ns []string)

TrimStrings trim string slice item.

func UnixTimeMilliSecond

func UnixTimeMilliSecond() float64

func WriteFile

func WriteFile(path string, content string) error

func WriteTarReaderToFile

func WriteTarReaderToFile(filename string, tarReader *tar.Reader)

Types

type Env

type Env uint
const (
	EnvDev Env = iota + 1
	EnvTest
	EnvPro
	EnvLive
)

func ToEnv

func ToEnv(sEnv string) Env

Jump to

Keyboard shortcuts

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