tools

package module
v3.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2023 License: Apache-2.0 Imports: 16 Imported by: 1

README

go-tools

Go常用工具集

go get -u github.com/shenguanjiejie/go-tools/v2

go版本<1.18, 请使用v2.2.2版本.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug debug

func Debugf

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

Debugf debug with template

func Delete

func Delete(urlStr string, values url.Values, obj interface{}, opions ...NetOptionFunc) error

Delete obj : body所序列化的对象, 指针类型, 如果为*http.Response类型, 则直接返回*http.Response

func Error

func Error(args ...interface{})

Error error

func Errorf

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

Errorf error with template

func FormDataPost

func FormDataPost(url string, data map[string]string, obj interface{}, options ...NetOptionFunc) error

FormDataPost obj : body所序列化的对象, 指针类型, 如果为*http.Response类型, 则直接返回*http.Response

func Get

func Get(urlStr string, values url.Values, obj interface{}, opions ...NetOptionFunc) error

Get obj : body所序列化的对象, 指针类型, 如果为*http.Response类型, 则直接返回*http.Response

func Info

func Info(args ...interface{})

Info info

func Infof

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

Infof info with template

func InternetCheck

func InternetCheck(netLogLevel NetLogLevel, switchAction ...func(isOnline bool)) bool

InternetCheck 网络检测是否在线

func LoadFile

func LoadFile(path string) []byte

LoadFile 加载文件

func Log

func Log(args ...interface{})

Log 带行号输出

func Logf

func Logf(format string, args ...interface{})

Logf 带行号格式输出

func Logln

func Logln(args ...interface{})

Logln 带行号换行输出

func MD5

func MD5(v string) string

MD5 md5

func Patch

func Patch(url string, data interface{}, obj interface{}, options ...NetOptionFunc) error

Patch obj : body所序列化的对象, 指针类型, 如果为*http.Response类型, 则直接返回*http.Response

func Post

func Post(url string, data interface{}, obj interface{}, config ...NetOptionFunc) error

Post obj : body所序列化的对象, 指针类型, 如果为*http.Response类型, 则直接返回*http.Response

func Put

func Put(url string, data interface{}, obj interface{}, options ...NetOptionFunc) error

Put obj : body所序列化的对象, 指针类型, 如果为*http.Response类型, 则直接返回*http.Response

func RemoveDuplicateElementArray

func RemoveDuplicateElementArray(sourceArray []string) []string

RemoveDuplicateElementArray 去重

func SaveFile

func SaveFile(path string, data []byte)

SaveFile 生成文件

func SetBaseFormat

func SetBaseFormat(block func(timeStr string, level string, funcName string, line int) (format string, args []interface{}))

SetBaseFormat 设置基本信息相关format格式, 默认为: "%s__%s__%s__第%d行__: " 和 []interface{}{timeStr, level, funName, codeLine}

func SetLogger

func SetLogger(yourLogger Logger)

SetLogger 设置日志输出实例

func TimeCost

func TimeCost(signs ...string) func()

TimeCost @brief:耗时统计函数

func WaitHandle

func WaitHandle(channel chan interface{}, goCount int, waitingFor func(), asyncHandle func(channelObj interface{}))

WaitHandle 阻塞型协程队列, 所有参数必传才执行

func Warn

func Warn(args ...interface{})

Warn warn

func Warnf

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

Warnf warn with template

Types

type LogOptionFunc added in v3.1.0

type LogOptionFunc func(o *logOptions)

LogOptionFunc for web

func LogCallerSkip

func LogCallerSkip(callerSkip int) LogOptionFunc

LogCallerSkip 输出的方法名的层级, 默认为0, 代表输出当前方法名, 如果要输出上层方法名(比如闭包内打印), 则该参数设置为LogCallerSkip(1)即可, 以此类推.

func LogCondition

func LogCondition(condition bool) LogOptionFunc

LogCondition 打印条件, 为true才打印, 默认true

func LogLineSkip

func LogLineSkip(lineSkip int) LogOptionFunc

LogLineSkip 输出的行号的层级, 默认为0, 代表输出当前所在代码块的行号, 如果要输出上层代码块的行号(比如闭包内打印), 则该参数设置为LogLineSkip(1)即可, 以此类推.

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})

	Infof(format string, args ...interface{})

	Warnf(format string, args ...interface{})

	Errorf(format string, args ...interface{})
}

Logger go-tools支持集成其他logger(调用SetLogger方法设置). 前提是要支持下方定义的Logger接口.

type NetLogLevel

type NetLogLevel int

NetLogLevel 日志级别

const (
	// 如果不需要打印, 请设置为NetLogNone, NetLogNil只是缺省值, 没有实际意义, 设置为NetLogNil相当于设置为NetLogAllWithoutObj
	NetLogNil  NetLogLevel = NetLogLevel(0)
	NetLogNone NetLogLevel = 1 << iota
	NetLogURL
	NetLogParams
	NetLogResponse
	// LogObj 打印反序列化后的obj
	NetLogObj
	NetLogError
	NetLogAllWithoutObj = NetLogURL | NetLogParams | NetLogResponse | NetLogError
	NetLogAll           = NetLogAllWithoutObj | NetLogObj
)

日志配置, 默认LogAllWithoutObj

type NetOptionFunc added in v3.1.0

type NetOptionFunc func(o *netOptions)

NetOptionFunc for web

func LogCallerSkipOption added in v3.1.0

func LogCallerSkipOption(logCallerSkip int) NetOptionFunc

LogCallerSkipOption 默认为0, 代表请求位置的方法所跳过的层数,如果想看tools内部打印所在的方法, 可以传-2

func LogLineSkipOption added in v3.1.0

func LogLineSkipOption(logLineSkip int) NetOptionFunc

LogLineSkipOption 默认为0, 代表请求位置的行号所跳过的层数,如果想看tools内部的打印所在的行, 可以传-2

func NetHeader added in v3.1.0

func NetHeader(header http.Header) NetOptionFunc

NetHeader header

func NetLogLevelOption added in v3.1.0

func NetLogLevelOption(netLogLevel NetLogLevel) NetOptionFunc

NetLogLevelOption default: NetLogAll

func Timeout added in v3.1.0

func Timeout(timeout time.Duration) NetOptionFunc

Timeout timeout

func UnmarshalPath added in v3.1.0

func UnmarshalPath(unmarshalPath []interface{}) NetOptionFunc

UnmarshalPath 仅当obj参数不为nil时有效, eg:[]interface{}{"a",0,"b"}, 将会解析a下面的第1个元素的b节点

Directories

Path Synopsis
* @Author: shenguanjiejie 835166018@qq.com * @Date: 2022-10-17 11:51:51 * @LastEditors: shenguanjiejie 835166018@qq.com * @LastEditTime: 2022-10-20 12:09:53 * @FilePath: /go-tools/main/main.go * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @Author: shenguanjiejie 835166018@qq.com * @Date: 2022-10-17 11:51:51 * @LastEditors: shenguanjiejie 835166018@qq.com * @LastEditTime: 2022-10-20 12:09:53 * @FilePath: /go-tools/main/main.go * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE

Jump to

Keyboard shortcuts

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