tools

package module
v0.0.0-...-2859479 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2023 License: Apache-2.0 Imports: 14 Imported by: 8

README

exciting-tool

Hex.pm

English | 简体中文

Excing-Tool is an ideal omnidirectional GO toolkit. The content involved includes: string processing (stitching, conversion, etc.), the log traversal of the structure (example), the automatic stitching and processing of the native SQL, and the more Convenient Map (under development), JSON parsing, HTTP request sending, and so on.

Remark information

The author does not guarantee to update the content in time, but will try his best to improve the document to help users use it.

Welcome everyone to help me ❤❤❤

important hint ⚠⚠⚠⚠⚠

☠ Need GO version 1.18 or more ☠

☀ You can use the code of the Lowversion branch in the low version ☀

Some functions may be unsafe, and some functions are only modified based on the GO native bag. Therefore, please pay attention to the use of some functions in actual use. I will mark as much as possible where possible problems may occur.

HOW TO USE

   go get https://github.com/iEvan-lhr/exciting-tool

Use the following code to construct a full -featured String

    tools.Make(str)

Common Functions

✔The following functions support the use of String, full -featured String, [] byte as the parameters


Function:
  Index(str any)           The next bid search, while supporting the Rune type retrieval
  Append(join any)         Add content to the string to support adding 
                           all basic types and extension basic types 
                           (including int, float, BOOL, int32, int16, string, str, byte, [] byte ...). 
                           Can be added (PS: pointer is passed in)
  Make(obj any)            If the structure is used to construct and the structure 
                           does not implement the String () method,
                           the full attribute printing will be performed. 
                           The example is as follows:
                           ----------User----------
                           Id:23132
                           Username:foo
                           Password:bar
                           Identity:324213
                           QrCode:982j32
                           DenKey:ansssss
                           TalkingKey:qwesad
                           ----------END----------
  FirstUpper()
  FirstLower()
  Check(str any)
  RemoveLastStr(lens)
  RemoveIndexStr(lens)
  Spilt(str any)
  CheckIsNull()

Error treatment


Function:
  ReturnValueByTwo()       The return value after the automatic processing, 
                           if the error is not empty, will panic(err)
  ReturnValue()            The return value after the automatic processing, 
                           if the error is not empty, will log(err)
  ExecGoFunc()             The error task that can be automatically defined in the asynchronous 
                           execution method internally is the asynchronous
                           execution of the error task that may occur
  ExecError()
  PanicError()
  logError()

Documentation

Index

Constants

View Source
const (
	TRUE  = "true"
	FALSE = "false"
)
View Source
const EndMessage = "----------END----------"
View Source
const IntSize = intSize

IntSize is the size in bits of an int or uint value.

View Source
const Select = "select * from "

Variables

View Source
var ErrRange = errors.New("value out of range")

ErrRange indicates that a value is out of range for the target type.

View Source
var ErrSyntax = errors.New("invalid syntax")

ErrSyntax indicates that a value does not have the right syntax for the target type.

Functions

func Check

func Check(model any) string

func Create

func Create(model any)

func DeferError

func DeferError(err error, exec interface{}, args ...interface{})

func Error

func Error(e interface{})

func ExecError

func ExecError(err error)

func ExecGoFunc

func ExecGoFunc(exec interface{}, args ...interface{})

ExecGoFunc 方法 参数

func IsGraphic

func IsGraphic(r rune) bool

IsGraphic reports whether the rune is defined as a Graphic by Unicode. Such characters include letters, marks, numbers, punctuation, symbols, and spaces, from categories L, M, N, P, S, and Zs.

func IsPrint

func IsPrint(r rune) bool

IsPrint reports whether the rune is defined as printable by Go, with the same definition as unicode.IsPrint: letters, numbers, punctuation, symbols and ASCII space.

func LockFunc

func LockFunc(name string, f func())

func LogError

func LogError(err error)

func Marshal

func Marshal(v interface{}) []byte

func MarshalMap

func MarshalMap(model any) map[string]string

func MarshalReq

func MarshalReq(r []any, v interface{}) interface{}

MarshalReq 用于从request中解析参数

func NaNValue

func NaNValue(v ...interface{}) interface{}

func Ok

func Ok(value any, ok bool) any

func PanicError

func PanicError(f ...func() error)

func ParseInt

func ParseInt(s []byte, base int, bitSize int) (i int64, err error)

ParseInt interprets a string s in the given base (0, 2 to 36) and bit size (0 to 64) and returns the corresponding value i.

The string may begin with a leading sign: "+" or "-".

If the base argument is 0, the true base is implied by the string's prefix following the sign (if present): 2 for "0b", 8 for "0" or "0o", 16 for "0x", and 10 otherwise. Also, for argument base 0 only, underscore characters are permitted as defined by the Go syntax for integer literals.

The bitSize argument specifies the integer type that the result must fit into. Bit sizes 0, 8, 16, 32, and 64 correspond to int, int8, int16, int32, and int64. If bitSize is below 0 or above 64, an error is returned.

The errors that ParseInt returns have concrete type *NumError and include err.Num = s. If s is empty or contains invalid digits, err.Err = ErrSyntax and the returned value is 0; if the value corresponding to s cannot be represented by a signed integer of the given size, err.Err = ErrRange and the returned value is the maximum magnitude integer of the appropriate bitSize and sign.

func ParseUint

func ParseUint(s []byte, base int, bitSize int) (uint64, error)

ParseUint is like ParseInt but for unsigned numbers.

A sign prefix is not permitted.

func Query

func Query(model any) string

Query 根据参数组装sql查询语句

func Quote

func Quote(s *String)

func ReturnValue

func ReturnValue(v ...interface{}) interface{}

func ReturnValueByTwo

func ReturnValueByTwo(v ...interface{}) interface{}

func Show

func Show(show any)

func UMarshal

func UMarshal(v, str interface{})

func UnMarshal

func UnMarshal(r *http.Request, v interface{}) interface{}

UnMarshal 用于从request中解析参数 Deprecated: 若使用iEvan-lhr/worker 构建request , 推荐使用 MarshalReq.

func Unmarshal

func Unmarshal(v interface{}, str interface{})

Unmarshal 公共方法 解析数据至空模板

func UnmarshalByOriginal

func UnmarshalByOriginal(v interface{}, str interface{})

func UnquoteChar

func UnquoteChar(s []byte, quote byte) (value rune, multibyte bool, tail []byte, err error)

UnquoteChar decodes the first character or byte in the escaped string or character literal represented by the string s. It returns four values:

  1. value, the decoded Unicode code point or byte value;
  2. multibyte, a boolean indicating whether the decoded character requires a multibyte UTF-8 representation;
  3. tail, the remainder of the string after the character; and
  4. an error that will be nil if the character is syntactically valid.

The second argument, quote, specifies the type of literal being parsed and therefore which escaped quote character is permitted. If set to a single quote, it permits the sequence \' and disallows unescaped '. If set to a double quote, it permits \" and disallows unescaped ". If set to zero, it does not permit either escape and allows both quote characters to appear unescaped.

func Update

func Update(model any)

Types

type Float

type Float struct {
	Number any
	Fmt    byte
	Pre    int
}

Float 此结构体用来进行自定义的Str拼接类型转换

type LockA

type LockA struct {
	Name string `json:"name"`
	// contains filtered or unexported fields
}

func Lock

func Lock(l any) LockA

type Map

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

func (Map) Set

func (m Map) Set(key, value any)

type NumError

type NumError struct {
	Func *String // the failing function (ParseBool, ParseInt, ParseUint, ParseFloat, ParseComplex)
	Num  *String // the input
	Err  error   // the reason the conversion failed (e.g. ErrRange, ErrSyntax, etc.)
}

A NumError records a failed conversion.

func (*NumError) Error

func (e *NumError) Error() string

func (*NumError) Unwrap

func (e *NumError) Unwrap() error

type ParseError

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

func F

func F(args ...interface{}) (vars *ParseError)

func ReturnError

func ReturnError(err error, succ func(...interface{}) *ParseError, fail func(...interface{}) *ParseError, args ...interface{}) (vars *ParseError)

func S

func S(args ...interface{}) (vars *ParseError)

func (*ParseError) Unmarshal

func (p *ParseError) Unmarshal(args ...interface{})

type Spider

type Spider struct {
	Values any
	Key    []byte
	Next   [255]*Spider
	// contains filtered or unexported fields
}

func MakeSpider

func MakeSpider(key any, value any) *Spider

func (*Spider) Add

func (s *Spider) Add(key any, value any)

func (*Spider) Get

func (s *Spider) Get(key any) any

func (*Spider) Len

func (s *Spider) Len() int

type String

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

func BytesString

func BytesString(b []byte) *String

func Do

func Do(url string, args ...interface{}) *String

Do 用于执行标准的请求方法,默认设置的header如下 header.Set("Accept", "*/*") header.Set("Accept-Language", "zh-CN,zh;q=0.9") header.Set("Connection", "keep-alive") header.Set("Content-Type", "application/json") header.Set("User-Agent", "PostmanRuntime/7.28.4")

func DoReq

func DoReq(r *http.Request, client ...*http.Client) *String

DoReq 用于执行需要自定义client的请求方法,例如使用https 可以设置信任证书等等 入参可选传入client 传入多个将拼接多次的执行结果

func DoUseHeader

func DoUseHeader(url string, header http.Header, args ...interface{}) *String

DoUseHeader 用于执行自定义header的请求方法 入参为请求地址、header、body及其他参数 允许header为nil 将会使用默认的header

func Itoa

func Itoa(i any) *String

func Make

func Make(value ...any) *String

Make 根据指定类型来构建一个String

func Save

func Save(model any) (result []*String)

Save 根据参数组装insert语句

func Strings

func Strings(str string) *String

Strings 根据字符串来构建一个String

func (*String) Append

func (s *String) Append(join ...any) *String

Append 拼接字符串后返回String

func (*String) AppendLens

func (s *String) AppendLens(join any) int

AppendLens 拼接字符串后返回String

func (*String) AppendSpilt

func (s *String) AppendSpilt(join ...any) *String

AppendSpilt 拼接字符串后返回String use AppendSpiltLR(",",24,23,22,21,11) get "24,23,22,21,11" or AppendSpiltLR(",",[]any...])

func (*String) AppendSpiltLR

func (s *String) AppendSpiltLR(join ...any) *String

AppendSpiltLR 拼接字符串后返回String use AppendSpiltLR(",","[","]",24,23,22,21,11) get "[24,23,22,21,11]" or AppendSpiltLR(",","[","]",[]any...]) use Make("insert userinfo values(").AppendSpiltLR(",", "'", "'", 4, 5, 6, 7, 8, 9, 10).Append(")") get insert userinfo values('4','5','6','7','8','9','10')

func (*String) Atoi

func (s *String) Atoi() (int, error)

Atoi 方法在实际使用中的效率近似接近strconv包中的方法,但如果是对同一个string对象进行多次转换 推荐使用strconv包中的方法

func (*String) Bytes

func (s *String) Bytes() []byte

Bytes 返回中文支持的字符

func (*String) Check

func (s *String) Check(str any) bool

Check 检查是否相等

func (*String) CheckIsNull

func (s *String) CheckIsNull() bool

CheckIsNull 检查字符串是否为空 只包含' '与'\t'与'\n'都会被视为不合法的值

func (*String) FirstLower

func (s *String) FirstLower()

FirstLower 首字母小写

func (*String) FirstLowerBackString

func (s *String) FirstLowerBackString() string

FirstLowerBackString 首字母小写后返回string

func (*String) FirstUpper

func (s *String) FirstUpper()

FirstUpper 首字母大写

func (*String) FirstUpperBackString

func (s *String) FirstUpperBackString() string

FirstUpperBackString 首字母大写后返回string

func (*String) FormatterNum

func (s *String) FormatterNum() (bool, string)

FormatterNum 格式化输出字符串

func (*String) Get

func (s *String) Get(model string) *String

Get 此方法用于取出括号中的内容 支持输入字符model需要为2 下标0为左字符 1为右字符 仅取出第一个匹配的结果

func (*String) GetAll

func (s *String) GetAll(model string) []string

GetAll 此方法用于取出括号中的内容 支持输入字符model需要为2 下标0为左字符 1为右字符 取出所有匹配的结果

func (*String) GetAllRune

func (s *String) GetAllRune(model string) []string

GetAllRune 此方法用于取出括号中的内容 支持输入字符model需要为2 下标0为左字符 1为右字符 取出所有匹配的结果

func (*String) GetByte

func (s *String) GetByte(index int) byte

GetByte 获取字符串的单个字符值

func (*String) GetContent

func (s *String) GetContent(label ...string) (content string)

GetContent 此方法用于取出固定字符串中的内容,例如<a>mess</a>,注意 仅仅取出第一个匹配项,若要取出所有,请使用GetContentAll GetContent("<a>","</a>")

func (*String) GetContentAll

func (s *String) GetContentAll(label ...string) (content, other []string, steps map[int]struct {
	Model int
	Index int
})

GetContentAll 此方法用于取出固定字符串中的内容,例如<a>mess</a>,注意 仅仅取出第一个匹配项,若要取出所有,请使用GetContentAll GetContentAll("<a>","</a>")

func (*String) GetRune

func (s *String) GetRune(model string) *String

GetRune 中文支持 此方法用于取出括号中的内容 支持输入字符model需要为2 下标0为左字符 1为右字符 仅取出第一个匹配的结果

func (*String) GetStr

func (s *String) GetStr(index, end int) string

GetStr 获取字符串的某个片段 返回String

func (*String) GetStrString

func (s *String) GetStrString(index, end int) *String

GetStrString 获取字符串的某个片段 返回String结构

func (*String) GetStrStringByRune

func (s *String) GetStrStringByRune(index, end int) *String

GetStrStringByRune 获取字符串的某个片段 返回String结构

func (*String) Grow

func (s *String) Grow(n int)

Grow 扩充大小

func (*String) Index

func (s *String) Index(str any) int

Index 返回数据中含有字串的下标 没有返回-1

func (*String) IsNumber

func (s *String) IsNumber() bool

IsNumber 用来检测字符串是否为数字

func (*String) Len

func (s *String) Len() int

Len 返回字符串长度

func (*String) LenByRune

func (s *String) LenByRune() int

LenByRune 返回含有中文的字符串长度

func (*String) Marshal

func (s *String) Marshal(model any)

func (*String) RemoveIndexRune

func (s *String) RemoveIndexRune(lens int)

RemoveIndexRune 移除头部固定长度的字符(中文支持)

func (*String) RemoveIndexStr

func (s *String) RemoveIndexStr(lens int)

RemoveIndexStr 移除头部固定长度的字符

func (*String) RemoveLastStr

func (s *String) RemoveLastStr(lens int)

RemoveLastStr 从尾部移除固定长度的字符

func (*String) RemoveLastStrByRune

func (s *String) RemoveLastStrByRune(lens int)

RemoveLastStrByRune 从尾部移除固定长度的字符 并且支持中文字符的移除

func (*String) ReplaceLastStr

func (s *String) ReplaceLastStr(lens int, str any)

ReplaceLastStr 从尾部移除固定长度的字符

func (*String) Runes

func (s *String) Runes() []rune

Runes 返回中文支持的字符

func (*String) Split

func (s *String) Split(str string) []string

Split 按照string片段来分割字符串 返回[]string

func (*String) SplitString

func (s *String) SplitString(str String) []*String

SplitString 按照*String来分割字符串 返回[]*String

func (*String) String

func (s *String) String() string

ToString 字符串转型输出

func (*String) UpdateLayout

func (s *String) UpdateLayout(layout ...string) (t string, err error)

func (*String) Write

func (s *String) Write(p []byte) (int, error)

WriteByte 写入[]Byte的数据

func (*String) WriteByte

func (s *String) WriteByte(c byte) error

WriteByte 写入Byte字符格式的数据

func (*String) WriteRune

func (s *String) WriteRune(r rune) (int, error)

WriteRune 写入Rune字符格式的数据

Jump to

Keyboard shortcuts

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