README ¶
exciting-tool
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
full-featured String
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
- Variables
- func Check(model any) string
- func Create(model any)
- func DeferError(err error, exec interface{}, args ...interface{})
- func Error(e interface{})
- func ExecError(err error)
- func ExecGoFunc(exec interface{}, args ...interface{})
- func IsGraphic(r rune) bool
- func IsPrint(r rune) bool
- func LockFunc(name string, f func())
- func LogError(err error)
- func Marshal(v interface{}) []byte
- func MarshalMap(model any) map[string]string
- func MarshalReq(r []any, v interface{}) interface{}
- func NaNValue(v ...interface{}) interface{}
- func Ok(value any, ok bool) any
- func PanicError(f ...func() error)
- func ParseInt(s []byte, base int, bitSize int) (i int64, err error)
- func ParseUint(s []byte, base int, bitSize int) (uint64, error)
- func Query(model any) string
- func Quote(s *String)
- func ReturnValue(v ...interface{}) interface{}
- func ReturnValueByTwo(v ...interface{}) interface{}
- func Show(show any)
- func UMarshal(v, str interface{})
- func UnMarshal(r *http.Request, v interface{}) interface{}
- func Unmarshal(v interface{}, str interface{})
- func UnmarshalByOriginal(v interface{}, str interface{})
- func UnquoteChar(s []byte, quote byte) (value rune, multibyte bool, tail []byte, err error)
- func Update(model any)
- type Float
- type LockA
- type Map
- type NumError
- type ParseError
- type Spider
- type String
- func BytesString(b []byte) *String
- func Do(url string, args ...interface{}) *String
- func DoReq(r *http.Request, client ...*http.Client) *String
- func DoUseHeader(url string, header http.Header, args ...interface{}) *String
- func Itoa(i any) *String
- func Make(value ...any) *String
- func Save(model any) (result []*String)
- func Strings(str string) *String
- func (s *String) Append(join ...any) *String
- func (s *String) AppendLens(join any) int
- func (s *String) AppendSpilt(join ...any) *String
- func (s *String) AppendSpiltLR(join ...any) *String
- func (s *String) Atoi() (int, error)
- func (s *String) Bytes() []byte
- func (s *String) Check(str any) bool
- func (s *String) CheckIsNull() bool
- func (s *String) FirstLower()
- func (s *String) FirstLowerBackString() string
- func (s *String) FirstUpper()
- func (s *String) FirstUpperBackString() string
- func (s *String) FormatterNum() (bool, string)
- func (s *String) Get(model string) *String
- func (s *String) GetAll(model string) []string
- func (s *String) GetAllRune(model string) []string
- func (s *String) GetByte(index int) byte
- func (s *String) GetContent(label ...string) (content string)
- func (s *String) GetContentAll(label ...string) (content, other []string, steps map[int]struct{ ... })
- func (s *String) GetRune(model string) *String
- func (s *String) GetStr(index, end int) string
- func (s *String) GetStrString(index, end int) *String
- func (s *String) GetStrStringByRune(index, end int) *String
- func (s *String) Grow(n int)
- func (s *String) Index(str any) int
- func (s *String) IsNumber() bool
- func (s *String) Len() int
- func (s *String) LenByRune() int
- func (s *String) Marshal(model any)
- func (s *String) RemoveIndexRune(lens int)
- func (s *String) RemoveIndexStr(lens int)
- func (s *String) RemoveLastStr(lens int)
- func (s *String) RemoveLastStrByRune(lens int)
- func (s *String) ReplaceLastStr(lens int, str any)
- func (s *String) Runes() []rune
- func (s *String) Split(str string) []string
- func (s *String) SplitString(str String) []*String
- func (s *String) String() string
- func (s *String) UpdateLayout(layout ...string) (t string, err error)
- func (s *String) Write(p []byte) (int, error)
- func (s *String) WriteByte(c byte) error
- func (s *String) WriteRune(r rune) (int, error)
Constants ¶
const ( TRUE = "true" FALSE = "false" )
const EndMessage = "----------END----------"
const IntSize = intSize
IntSize is the size in bits of an int or uint value.
const Select = "select * from "
Variables ¶
var ErrRange = errors.New("value out of range")
ErrRange indicates that a value is out of range for the target type.
var ErrSyntax = errors.New("invalid syntax")
ErrSyntax indicates that a value does not have the right syntax for the target type.
Functions ¶
func DeferError ¶
func DeferError(err error, exec interface{}, args ...interface{})
func IsGraphic ¶
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 ¶
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 MarshalMap ¶
func PanicError ¶
func PanicError(f ...func() error)
func ParseInt ¶
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 ¶
ParseUint is like ParseInt but for unsigned numbers.
A sign prefix is not permitted.
func ReturnValue ¶
func ReturnValue(v ...interface{}) interface{}
func ReturnValueByTwo ¶
func ReturnValueByTwo(v ...interface{}) interface{}
func UnMarshal ¶
UnMarshal 用于从request中解析参数 Deprecated: 若使用iEvan-lhr/worker 构建request , 推荐使用 MarshalReq.
func UnmarshalByOriginal ¶
func UnmarshalByOriginal(v interface{}, str interface{})
func UnquoteChar ¶
UnquoteChar decodes the first character or byte in the escaped string or character literal represented by the string s. It returns four values:
- value, the decoded Unicode code point or byte value;
- multibyte, a boolean indicating whether the decoded character requires a multibyte UTF-8 representation;
- tail, the remainder of the string after the character; and
- 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.
Types ¶
type LockA ¶
type LockA struct { Name string `json:"name"` // contains filtered or unexported fields }
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.
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 ¶
type String ¶
type String struct {
// contains filtered or unexported fields
}
func BytesString ¶
func Do ¶
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 DoUseHeader ¶
DoUseHeader 用于执行自定义header的请求方法 入参为请求地址、header、body及其他参数 允许header为nil 将会使用默认的header
func (*String) AppendSpilt ¶
AppendSpilt 拼接字符串后返回String use AppendSpiltLR(",",24,23,22,21,11) get "24,23,22,21,11" or AppendSpiltLR(",",[]any...])
func (*String) AppendSpiltLR ¶
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) CheckIsNull ¶
CheckIsNull 检查字符串是否为空 只包含' '与'\t'与'\n'都会被视为不合法的值
func (*String) FirstLowerBackString ¶
FirstLowerBackString 首字母小写后返回string
func (*String) FirstUpperBackString ¶
FirstUpperBackString 首字母大写后返回string
func (*String) GetAllRune ¶
GetAllRune 此方法用于取出括号中的内容 支持输入字符model需要为2 下标0为左字符 1为右字符 取出所有匹配的结果
func (*String) GetContent ¶
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) GetStrString ¶
GetStrString 获取字符串的某个片段 返回String结构
func (*String) GetStrStringByRune ¶
GetStrStringByRune 获取字符串的某个片段 返回String结构
func (*String) RemoveIndexRune ¶
RemoveIndexRune 移除头部固定长度的字符(中文支持)
func (*String) RemoveIndexStr ¶
RemoveIndexStr 移除头部固定长度的字符
func (*String) RemoveLastStrByRune ¶
RemoveLastStrByRune 从尾部移除固定长度的字符 并且支持中文字符的移除
func (*String) ReplaceLastStr ¶
ReplaceLastStr 从尾部移除固定长度的字符
func (*String) SplitString ¶
SplitString 按照*String来分割字符串 返回[]*String