zaia

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: MIT Imports: 34 Imported by: 0

README

base library

current version

v1.0.5

Documentation

Index

Constants

View Source
const MaxIterations = 5000

Variables

View Source
var (
	// Epoch is set to the twitter snowflake epoch of Nov 04 2010 01:42:54 UTC in milliseconds
	// You may customize this to set a different epoch for your application.
	Epoch int64 = 1498612200000

	// NodeBits holds the number of bits to use for Node
	// Remember, you have a total 14 bits to share between Node/Step
	NodeBits uint8 = 6

	// StepBits holds the number of bits to use for Step
	// Remember, you have a total 14 bits to share between Node/Step
	StepBits uint8 = 8
)
View Source
var ErrInvalidBase32 = errors.New("invalid base32")

ErrInvalidBase32 is returned by ParseBase32 when given an invalid []byte

View Source
var ErrInvalidBase58 = errors.New("invalid base58")

ErrInvalidBase58 is returned by ParseBase58 when given an invalid []byte

Functions

func AppendToFile

func AppendToFile(file *os.File, appendContent string)

func Base64ToFile

func Base64ToFile(fileData string) (*os.File, error)

func ChangeWorkPath

func ChangeWorkPath(wp string)

func ConvertPNG2JPG

func ConvertPNG2JPG(pngFileName string, jpgFileName string) error

func ConvertToFloat32

func ConvertToFloat32(number string) float32

func ConvertToFloat64

func ConvertToFloat64(number string) float64

func ConvertToInt

func ConvertToInt(number string) int

func ConvertToInt32

func ConvertToInt32(number string) int32

func ConvertToInt64

func ConvertToInt64(number string) int64

func ConvertToUint

func ConvertToUint(number string) uint

func CopyFile

func CopyFile(src string, dst string) error

func DirectoryExists

func DirectoryExists(path string) (exists bool, err error)

func DumpBytes

func DumpBytes(fileName string, data []byte) error

func DumpFormToFile

func DumpFormToFile(file *multipart.FileHeader, fullPath string, fileName string) (string, error)

func DumpInterface

func DumpInterface(fileName string, data interface{}) error

func DumpString

func DumpString(fileName string, data string) error

func ExecBash

func ExecBash(c string) error

func ExecCmd

func ExecCmd(timeout time.Duration, name string, arg ...string) (string, error)

func ExecCommand

func ExecCommand(timeout time.Duration, name string, arg ...string) ([]string, error)

func FileExists

func FileExists(path string) (exists bool, err error)

func FileMD5

func FileMD5(filePath string) (string, error)

func FileSize

func FileSize(path string) (size int64, err error)

func FileWithExt

func FileWithExt(fileName string, ext string) bool

func FormatHumanDisplayTime

func FormatHumanDisplayTime(time int64) string

func FormatHumanTime

func FormatHumanTime(time int64) string

func FormatMessage

func FormatMessage(template string, args ...interface{}) string

func FormatTime

func FormatTime(time int64) string

func GenSignature

func GenSignature(params url.Values, secretKey string) string

func GetCallerFrame

func GetCallerFrame(skip int) (frame runtime.Frame, ok bool)

func GetCurrentServerIp

func GetCurrentServerIp(serverAddress string) string

func GetExeDir

func GetExeDir() string

func GetHostName

func GetHostName() string

func GetImgBase64

func GetImgBase64(path string) (baseImg string, err error)

func GetLocalImageBase64

func GetLocalImageBase64(path string) (string, error)

func GetNextId

func GetNextId() int64

func GetTaskSubFolder

func GetTaskSubFolder(rootPath string, taskId int64) string

func GetTempFileName

func GetTempFileName(pattern string) (string, error)

func GetUrlImgBase64

func GetUrlImgBase64(path string) (baseImg string, err error)

func GoId

func GoId() int64

func HttpAddParam

func HttpAddParam(address string, k string, v string) (string, error)

func HttpPost

func HttpPost(url string, content string, timeout time.Duration) error

func HttpRequest

func HttpRequest(url string, post bool, content []byte, contentType string, timeout time.Duration, headerCallback func(header http.Header)) ([]byte, error)

func Int64Abs

func Int64Abs(n int64) int64

func Int64Max

func Int64Max(x, y int64) int64

func Int64Min

func Int64Min(x, y int64) int64

func IsLocalHost

func IsLocalHost(addr string) bool

func IsNumeric

func IsNumeric(number string) bool

func ListFSCmd

func ListFSCmd(fs string) (map[string]string, error)

func ListFiles

func ListFiles(folderName string, end string) ([]string, error)

func ListImageFiles

func ListImageFiles(folderName string) ([]string, error)

func MountCmd

func MountCmd(c string) error

func NetworkStream

func NetworkStream(name string) bool

func NewRat

func NewRat(val float64, iterations int64, stepPrecision float64) *big.Rat

func NewRatI

func NewRatI(val float64, iterations int64) *big.Rat

func NewRatP

func NewRatP(val float64, stepPrecision float64) *big.Rat

func Parse

func Parse(fileName string, outFileName string, mapInfo map[string]interface{}) error

func ParseJsonArray

func ParseJsonArray(a []interface{}, f func(k string, v interface{}))

func ParseJsonMap

func ParseJsonMap(m map[string]interface{}, f func(k string, v interface{}))

func ParseTranscoderProgress

func ParseTranscoderProgress(s string, prefix string) (int32, float32, bool)

func PathExists

func PathExists(path string) (exists bool, err error)

func PrintMemUsage

func PrintMemUsage()

func RSABase64Decrypt

func RSABase64Decrypt(encodedData string, publicKey string) (string, error)

func RSABase64Encrypt

func RSABase64Encrypt(data []byte, publicKey string) (string, error)

func ReadFileToByte

func ReadFileToByte(fileName string) []byte

func ReadFileToString

func ReadFileToString(fileName string) string

func RsaPublicDecrypt

func RsaPublicDecrypt(pubKey *rsa.PublicKey, data []byte) []byte

func RunBash

func RunBash(c string) (string, error)

func SFormatMessage

func SFormatMessage(template string, fmtArgs []interface{}) string

func SplitMultiLineString

func SplitMultiLineString(is string, removeEmpty bool) []string

func SplitString

func SplitString(s string, sep string) []string

func ToJpeg

func ToJpeg(imageBytes []byte) ([]byte, error)

func ToPrintString

func ToPrintString(v interface{}) string

func ToString

func ToString(v interface{}) string

func TruncateString

func TruncateString(str string, length int, unicodeMode bool) string

func UnmountCmd

func UnmountCmd(c string) error

func UrlToFile

func UrlToFile(fullURLFile string, fullName string, fileExt string) (*os.File, error)

func WriteBase64ToFileName

func WriteBase64ToFileName(base64Data string, targetFileName string) error

func WriteJsonToFile

func WriteJsonToFile(fileName string, v interface{}) error

func XmlEscape

func XmlEscape(s string) string

Types

type ID

type ID int64

An ID is a custom type used for a snowflake ID. This is used so we can attach methods onto the ID.

func ParseBase2

func ParseBase2(id string) (ID, error)

ParseBase2 converts a Base2 string into a snowflake ID

func ParseBase32

func ParseBase32(b []byte) (ID, error)

ParseBase32 parses a base32 []byte into a snowflake ID NOTE: There are many different base32 implementations so becareful when doing any interoperation.

func ParseBase36

func ParseBase36(id string) (ID, error)

ParseBase36 converts a Base36 string into a snowflake ID

func ParseBase58

func ParseBase58(b []byte) (ID, error)

ParseBase58 parses a base58 []byte into a snowflake ID

func ParseBase64

func ParseBase64(id string) (ID, error)

ParseBase64 converts a base64 string into a snowflake ID

func ParseBytes

func ParseBytes(id []byte) (ID, error)

ParseBytes converts a byte slice into a snowflake ID

func ParseInt64

func ParseInt64(id int64) ID

ParseInt64 converts an int64 into a snowflake ID

func ParseIntBytes

func ParseIntBytes(id [8]byte) ID

ParseIntBytes converts an array of bytes encoded as big endian integer as a snowflake ID

func ParseString

func ParseString(id string) (ID, error)

ParseString converts a string into a snowflake ID

func (ID) Base2

func (f ID) Base2() string

Base2 returns a string base2 of the snowflake ID

func (ID) Base32

func (f ID) Base32() string

Base32 uses the z-base-32 character set but encodes and decodes similar to base58, allowing it to create an even smaller result string. NOTE: There are many different base32 implementations so becareful when doing any interoperation.

func (ID) Base36

func (f ID) Base36() string

Base36 returns a base36 string of the snowflake ID

func (ID) Base58

func (f ID) Base58() string

Base58 returns a base58 string of the snowflake ID

func (ID) Base64

func (f ID) Base64() string

Base64 returns a base64 string of the snowflake ID

func (ID) Bytes

func (f ID) Bytes() []byte

Bytes returns a byte slice of the snowflake ID

func (ID) Int64

func (f ID) Int64() int64

Int64 returns an int64 of the snowflake ID

func (ID) IntBytes

func (f ID) IntBytes() [8]byte

IntBytes returns an array of bytes of the snowflake ID, encoded as a big endian integer.

func (ID) MarshalJSON

func (f ID) MarshalJSON() ([]byte, error)

MarshalJSON returns a json byte array string of the snowflake ID.

func (ID) Node

func (f ID) Node() int64

Node returns an int64 of the snowflake ID node number

func (ID) Step

func (f ID) Step() int64

Step returns an int64 of the snowflake step (or sequence) number

func (ID) String

func (f ID) String() string

String returns a string of the snowflake ID

func (ID) Time

func (f ID) Time() int64

Time returns an int64 unix timestamp in milliseconds of the snowflake ID time

func (*ID) UnmarshalJSON

func (f *ID) UnmarshalJSON(b []byte) error

UnmarshalJSON converts a json byte array of a snowflake ID into an ID type.

type JSONSyntaxError

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

A JSONSyntaxError is returned from UnmarshalJSON if an invalid ID is provided.

func (JSONSyntaxError) Error

func (j JSONSyntaxError) Error() string

type Job

type Job interface {
	Execute() error
	Stop() error
	Equal(t interface{}) bool
}

type Node

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

A Node struct holds the basic information needed for a snowflake generator node

func NewNode

func NewNode(node int64) (*Node, error)

NewNode returns a new snowflake node that can be used to generate snowflake IDs

func (*Node) Generate

func (n *Node) Generate() ID

Generate creates and returns a unique snowflake ID To help guarantee uniqueness - Make sure your system is keeping accurate system time - Make sure you never have multiple nodes running with the same node ID

type Pool

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

func NewPool

func NewPool(maxWorkerNum int32, maxWaitingNum int32) *Pool

func (*Pool) Add

func (p *Pool) Add(t Job)

func (*Pool) Close

func (p *Pool) Close()

func (*Pool) Exist

func (p *Pool) Exist(t Job) bool

func (*Pool) ExistPending

func (p *Pool) ExistPending(t Job) bool

func (*Pool) Remove

func (p *Pool) Remove(t Job) bool

func (*Pool) Run

func (p *Pool) Run()

func (*Pool) RunningTasks

func (p *Pool) RunningTasks() int32

func (*Pool) SetMaxWorkerNumber

func (p *Pool) SetMaxWorkerNumber(maxWorkerNum int32)

func (*Pool) WaitAllDone

func (p *Pool) WaitAllDone()

func (*Pool) WaitingTasks

func (p *Pool) WaitingTasks() int32

type Process

type Process struct {
	ExecPath   string
	Args       []string
	Pid        int
	Cmd        *exec.Cmd
	ExitState  *os.ProcessState
	StdinPipe  io.WriteCloser
	StdoutPipe io.ReadCloser
	StderrPipe io.ReadCloser
	Cancel     context.CancelFunc
	StopSignal chan bool
	ExitCode   int
}

func CreateProcess

func CreateProcess(timeout time.Duration, dir string, name string, outReaderHandler func(string), errReaderHandler func(string), args ...string) (*Process, error)

func StartProcess

func StartProcess(timeout time.Duration, dir string, name string, outReaderHandler func(string), errReaderHandler func(string), args ...string) (*Process, error)

func (*Process) Close

func (proc *Process) Close()

func (*Process) ReadAll

func (proc *Process) ReadAll() (stdout []byte, stderr []byte, err error)

func (*Process) Stop

func (proc *Process) Stop(kill bool) error

func (*Process) Wait

func (proc *Process) Wait()

type Task

type Task[T any] struct {
	TaskMapList    map[string]*T
	ProjectName    string
	StatusCallback func(taskId string, t *T)
	// contains filtered or unexported fields
}

func NewTask

func NewTask[T any]() *Task[T]

func (*Task[T]) Dump

func (tc *Task[T]) Dump()

func (*Task[T]) Find added in v1.0.6

func (tc *Task[T]) Find(callback func(t *T) bool) (string, *T)

func (*Task[T]) Get

func (tc *Task[T]) Get(taskId string) *T

func (*Task[T]) Load

func (tc *Task[T]) Load()

func (*Task[T]) Remove

func (tc *Task[T]) Remove(taskId string)

func (*Task[T]) Set

func (tc *Task[T]) Set(taskId string, t *T)

Jump to

Keyboard shortcuts

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