tool

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: Apache-2.0 Imports: 28 Imported by: 2

Documentation

Index

Constants

View Source
const (
	GET    = "GET"
	PUT    = "PUT"
	POST   = "POST"
	DELETE = "DELETE"
)
View Source
const (
	ContentType               = "Content-Type"
	ApplicationJson           = "application/json"
	ApplicationFromUrlencoded = "application/x-www-from-urlencoded"
)

Variables

View Source
var Converters = []copier.TypeConverter{
	{
		SrcType: time.Time{},
		DstType: copier.String,
		Fn: func(src interface{}) (interface{}, error) {
			s, ok := src.(time.Time)

			if !ok {
				return nil, errors.New("src type not matching")
			}

			return s.Format(time.RFC3339), nil
		},
	},
	{
		SrcType: copier.String,
		DstType: copier.Int,
		Fn: func(src interface{}) (interface{}, error) {
			s, ok := src.(string)

			if !ok {
				return nil, errors.New("src type not matching")
			}

			return strconv.Atoi(s)
		},
	},
	{
		SrcType: copier.String,
		DstType: copier.Bool,
		Fn: func(src interface{}) (interface{}, error) {
			s, ok := src.(string)

			if !ok {
				return nil, errors.New("src type not matching")
			}

			return strconv.ParseBool(s)
		},
	},
}

Functions

func Convert

func Convert(source interface{}, target interface{})

Convert 通过JSON赋值

func ConvertStructToMap

func ConvertStructToMap(in interface{}) map[string]string

func DurationToDateTime

func DurationToDateTime(timeData uint64) time.Time

func EntryIdToString

func EntryIdToString(id cron.EntryID) string

EntryIdToString EntryID转string

func FloatConv

func FloatConv(num float64) float64

func GenSnowflakeID added in v0.0.2

func GenSnowflakeID() int64

GenSnowflakeID 生成雪花算法id machineId 工作id

func GetACHttpRequest

func GetACHttpRequest() *resty.Request

func GetDirSize

func GetDirSize(path string) (int64, error)

DirSize 获取整体文件夹大小

func GetGVR

GetGVR 获取GVR

func GetParticipantId added in v0.0.2

func GetParticipantId(filePath string) (int64, error)

GetParticipantId 获取本地配置文件中的ParticipantId

func GetTimeDurationString

func GetTimeDurationString(startTime string, endTime string) string

func HttpClient

func HttpClient(method string, url string, payload io.Reader, token string) ([]byte, error)

func HttpClientStatusCode

func HttpClientStatusCode(method string, url string, payload io.Reader, token string) (int, error)

func HttpClientWithBodyAndCode

func HttpClientWithBodyAndCode(method string, url string, payload io.Reader, token string) (int, []byte, error)

func HttpClientWithQueries

func HttpClientWithQueries[T any](method string, url string, payload io.Reader, token string, param T) ([]byte, error)

func HttpClientWithScreen

func HttpClientWithScreen(method string, url string, payload io.Reader) (int, []byte, error)

func HttpGet

func HttpGet(method string, url string) ([]byte, error)

func HttpPost

func HttpPost(url string, data interface{}) (content string, err error)

发送POST请求 url:请求地址,data:POST请求提交的数据,contentType:请求体格式,如:application/json content:请求放回的内容

func InitSnowflake added in v0.0.2

func InitSnowflake(machineID int64) (err error)

func Int64ToString

func Int64ToString(value int64) string

Int64ToString int64转string

func K8sUnstructured

func K8sUnstructured(dataString string, target interface{})

func NewHttpsClient

func NewHttpsClient() *resty.Client

func PathExists

func PathExists(path string) (bool, error)

PathExists 判断文件夹是否存在

func RemoveDuplication_map

func RemoveDuplication_map(arr []string) []string

removeDuplication_map 去重数组

func RunTimeToSeconds

func RunTimeToSeconds(runTime string) int

func StringToFloat64 added in v0.0.2

func StringToFloat64(value string) float64

func StringToInt

func StringToInt(value string) int

func StringToInt64 added in v0.0.2

func StringToInt64(value string) int64

func TimeRemoveZone

func TimeRemoveZone(tm time.Time) time.Time

func TimeStringRemoveZone

func TimeStringRemoveZone(tm string) string

func TimeStringToGoTime

func TimeStringToGoTime(tm string) time.Time

TimeStringToGoTime 时间格式字符串转换

func UpdateParticipantId added in v0.0.2

func UpdateParticipantId(filePath string, value string) error

UpdateParticipantId 更新本地配置文件ParticipantId

func Yaml2struct

func Yaml2struct(fileHeader *multipart.FileHeader, req interface{}) error

Types

type PConfig added in v0.0.2

type PConfig struct {
	ParticipantId int64
}

Jump to

Keyboard shortcuts

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