base

package
v0.0.55 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

* @Author: lisheng * @Date: 2022-10-29 11:14:13 * @LastEditTime: 2023-02-28 19:51:19 * @LastEditors: lisheng * @Description: covert A类型 To B类型 * @FilePath: /go-kit/base/convert.go

* @Author: lisheng * @Date: 2023-01-16 16:21:31 * @LastEditTime: 2023-01-17 15:19:31 * @LastEditors: lisheng * @Description: * @FilePath: /go-kit/base/error.go

* @Author: lisheng * @Date: 2022-10-29 11:16:36 * @LastEditTime: 2022-10-29 11:16:46 * @LastEditors: lisheng * @Description: 文件创建和检测 * @FilePath: /gitee.com/liqiyuworks/go-kit/base/file.go

* @Author: lisheng * @Date: 2022-10-14 23:34:41 * @LastEditTime: 2022-11-18 09:57:18 * @LastEditors: lisheng * @Description: 日志模块 * @FilePath: /gitee.com/liqiyuworks/go-kit/base/log.go

* @Author: lisheng * @Date: 2022-10-29 11:42:37 * @LastEditTime: 2022-10-29 11:47:17 * @LastEditors: lisheng * @Description: 合并各种类型模块 * @FilePath: /gitee.com/liqiyuworks/go-kit/base/merge.go

* @Author: lisheng * @Date: 2022-10-11 14:29:08 * @LastEditTime: 2022-11-02 23:02:33 * @LastEditors: lisheng * @Description: 通用json返回模块 * @FilePath: /gitee.com/liqiyuworks/go-kit/base/response.go

* @Author: lisheng * @Date: 2022-10-29 11:20:48 * @LastEditTime: 2022-10-29 11:58:45 * @LastEditors: lisheng * @Description: 保留小数的精度 * @FilePath: /gitee.com/liqiyuworks/go-kit/base/round.go

* @Author: lisheng * @Date: 2023-01-16 16:38:45 * @LastEditTime: 2023-02-24 17:22:42 * @LastEditors: lisheng * @Description: * @FilePath: /go-kit/base/sort.go

* @Author: lisheng * @Date: 2022-10-29 11:21:17 * @LastEditTime: 2022-12-23 17:30:20 * @LastEditors: lisheng * @Description: * @FilePath: /go-kit/base/string.go

* @Author: lisheng * @Date: 2022-10-29 11:18:30 * @LastEditTime: 2022-12-17 16:59:09 * @LastEditors: lisheng * @Description: 时间模块 * @FilePath: /go-kit/base/time.go

Index

Constants

This section is empty.

Variables

View Source
var (
	Glog = logrus.New()
)

Functions

func CheckDir

func CheckDir(dirPath string) error

func CheckErr

func CheckErr(err error, msg string)

func ConvertByteToString

func ConvertByteToString(bytes []byte) string

*

  • @description: ConvertByteToString
  • @param {[]byte} bytes
  • @return {*}
  • @author: liqiyuWorks

func ConvertCamelToCase

func ConvertCamelToCase(name string) string

*

  • @description: 驼峰式写法转为下划线写法
  • @param {string} name
  • @return {*}
  • @author: liqiyuWorks

func ConvertCamelToSlash

func ConvertCamelToSlash(name string) string

*

  • @description: 把骆驼变成斜杠
  • @param {string} name
  • @return {*}
  • @author: liqiyuWorks

func ConvertCaseToCamel

func ConvertCaseToCamel(name string) string

*

  • @description: 下划线写法转为驼峰写法
  • @param {string} name
  • @return {*}
  • @author: liqiyuWorks

func ConvertJsonToMap

func ConvertJsonToMap(stringData string, mapData *map[string]interface{})

*

  • @description: ConvertJsonToMap
  • @param {string} stringData
  • @param {*map[string]interface{}} mapData
  • @return {*}
  • @author: liqiyuWorks

func ConvertMapToJson

func ConvertMapToJson(mapData map[string]interface{}) string

*

  • @description: ConvertMapToJson
  • @param {map[string]interface{}} mapData
  • @return {*}
  • @author: liqiyuWorks

func ConvertStringToByte

func ConvertStringToByte(s string) []byte

*

  • @description: ConvertStringToByte
  • @param {string} s
  • @return {*}
  • @author: liqiyuWorks

func ConvertStructToMap

func ConvertStructToMap(i interface{}, defaultValue interface{}, ret interface{})

*

  • @description: Struct转Map
  • @param {interface{}} i
  • @param {interface{}} defaultValue: nil
  • @param {interface{}} ret
  • @return {*}
  • @author: liqiyuWorks

func ConvertToFloat64

func ConvertToFloat64(i interface{}, defaultValue float64) (ret float64)

*

  • @description: interface转float64
  • @param {interface{}} i
  • @param {float64} defaultValue:0
  • @return {*}
  • @author: liqiyuWorks

func ConvertToInt

func ConvertToInt(i interface{}, defaultValue int) int

*

  • @description: interface转int
  • @param {interface{}} i
  • @param {int} defaultValue: 0
  • @return {*}
  • @author: liqiyuWorks

func ConvertToInt64

func ConvertToInt64(i interface{}, defaultValue int64) (ret int64)

*

  • @description: interface转int64
  • @param {interface{}} i
  • @param {int64} defaultValue:0
  • @return {*}
  • @author: liqiyuWorks

func ConvertToString

func ConvertToString(i interface{}, defaultValue string) (ret string)

*

  • @description: interface转string
  • @param {interface{}} i
  • @param {string} defaultValue: ""
  • @return {*}
  • @author: liqiyuWorks

func CreateLogFile

func CreateLogFile()

func Decimal1

func Decimal1(num float64) float64

func Decimal2

func Decimal2(num float64) float64

*

  • @description: 保留float64两位小数
  • @param {float64} num
  • @return {*}
  • @author: liqiyuWorks

func GetDate

func GetDate() string

func GetDateByLocation

func GetDateByLocation(location *time.Location) string

func GetDateHour

func GetDateHour() string

func GetDateNum

func GetDateNum(location *time.Location) int

func GetDateNum2

func GetDateNum2(now *time.Time) int

func GetDayEndTimeLocal

func GetDayEndTimeLocal() time.Time

func GetDayEndTimeUtc

func GetDayEndTimeUtc() time.Time

func GetLastHourToTs

func GetLastHourToTs(ts int64) (lastHour int64)

*

  • @description: 计算最接近某小时的时间戳
  • @param {int} ts
  • @return {*}
  • @author: liqiyuWorks

func GetMonthName

func GetMonthName(location *time.Location) int

func GetMonthlyDayCount

func GetMonthlyDayCount(year int, month int) int

计算某年某月的天数

func GetNextDayStartTimeByLocation

func GetNextDayStartTimeByLocation(location *time.Location) time.Time

func GetNextDayStartTimeLocal

func GetNextDayStartTimeLocal() time.Time

func GetNextDayStartTimeUtc

func GetNextDayStartTimeUtc() time.Time

func GetSpecifiedNumToTs

func GetSpecifiedNumToTs(ts int64, hour int64) (SpecifiedHour int64)

*

  • @description: 计算最接近n个小时的时间戳, 前后匹配,找到最接近的n小时的时刻
  • @param {int64} ts
  • @param {int64} hour
  • @return {*}
  • @author: liqiyuWorks

func GetTimeByTz

func GetTimeByTz(tz string) (*time.Time, error)

func GetTimeStampMs

func GetTimeStampMs() string

func GetTimeStampSec

func GetTimeStampSec() string

func GetWeekDay

func GetWeekDay(location *time.Location) int32

func GetWeekName

func GetWeekName(location *time.Location) int

func In

func In(target string, strList []string) bool

*

  • @description: 检查一个字符串是否存在于一个数组中
  • @param {string} target
  • @param {[]string} strList
  • @return {*}
  • @author: liqiyuWorks

func InitLogger

func InitLogger()

func Lcfirst

func Lcfirst(str string) string

*

  • @description: 首字母小写
  • @param {string} str
  • @return {*}
  • @author: liqiyuWorks

func MergeMaps

func MergeMaps(mObj ...map[string]interface{}) map[string]interface{}

*

  • @description: 合并maps
  • @param {...map[string]interface{}} mObj
  • @return {*}
  • @author: liqiyuWorks

func MergeStrings

func MergeStrings(strs ...string) string

*

  • @description: 合并字符串
  • @param {...string} strs
  • @return {*}
  • @author: liqiyuWorks

func MkDir

func MkDir(dirPath string) error

func PathExist

func PathExist(path string) error

func PrintPerformTimeConsuming

func PrintPerformTimeConsuming(funcName string, startTime time.Time)

func SortSlice

func SortSlice[T constraints.Ordered](s []T, reverse bool)

*

  • @description: 切片的排序,可逆序
  • @return {*}
  • @author: liqiyuWorks

func StringSub

func StringSub(str string, n int, reverse bool) string

*

  • @description: 截取字符串
  • @param {string} str
  • @param {int} n
  • @param {bool} reverse: true: 反向切片, false: 正向切片
  • @return {*}
  • @author: liqiyuWorks

func StringSubA2B

func StringSubA2B(str string, a int, b int, reverse bool) string

*

  • @description: StringSubA2B
  • @param {string} str
  • @param {int} a
  • @param {int} b
  • @param {bool} reverse fasle:正序 true 逆序
  • @return {*}
  • @author: liqiyuWorks

func TimeName

func TimeName(t time.Time) string

func Ucfirst

func Ucfirst(str string) string

*

  • @description: 首字母大写
  • @return {*}
  • @author: liqiyuWorks

Types

type BaseResponse

type BaseResponse struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg,omitempty"`
	Data interface{} `json:"data"`
}

type Buffer

type Buffer struct {
	*bytes.Buffer
}

内嵌bytes.Buffer,支持连写

func NewBuffer

func NewBuffer() *Buffer

func (*Buffer) Append

func (b *Buffer) Append(i interface{}) *Buffer

type MyInt

type MyInt interface {
	int | int8 | int16 | int32 | int64
}

Jump to

Keyboard shortcuts

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