gohelper

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2021 License: MIT Imports: 14 Imported by: 1

README

gohelper

介绍

golang常用转换

软件架构

软件架构说明

安装教程
  1. xxxx
  2. xxxx
  3. xxxx
使用说明
  1. xxxx
  2. xxxx
  3. xxxx
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Overview

* string functions

* System info

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ByteToUnitSize

func ByteToUnitSize(Size interface{}) (float64, string)

字节自动转换为B/KB/MB/GB

func CpuUsage

func CpuUsage() string

func DeleteExtraSpace

func DeleteExtraSpace(s string) string

* 删除多余空格 * 2019/05/05

func FileUsage

func FileUsage() []interface{}

func FloatAdd

func FloatAdd(str ...interface{}) float64

*

  • 数值相加
  • @param str 加数,加数...
  • 2020/05/22
  • gz

func FloatMul

func FloatMul(str ...interface{}) float64

*

  • float相乘
  • @param str 被除数,除数,保留小数位数
  • 2020/05/25
  • gz

func FloatQuo

func FloatQuo(str ...interface{}) float64

*

  • float相除
  • @param str 被除数,除数,保留小数位数
  • 2020/05/25
  • gz

func FloatSub

func FloatSub(str ...interface{}) float64

*

  • float相减
  • @param str 被减数,减数...
  • 2020/05/22
  • gz

func FormatDate

func FormatDate(str string) string

func FormatDateTime

func FormatDateTime(str string) string

func FormatUUID

func FormatUUID(buf []byte) (string, error)

func GenerateRandomBytes

func GenerateRandomBytes(size int) ([]byte, error)

GenerateRandomBytes is used to generate random bytes of given size.

func GenerateUUID

func GenerateUUID() (string, error)

GenerateUUID is used to generate a random UUID

func GetNetConfig

func GetNetConfig() []interface{}

*

*网络配置

func GetPage

func GetPage(pageNum, pageSize interface{}) (string, string)

*

  • 根据第几页计算从第几行开始
  • @param pageNum 第几页
  • @param pageSize 每页几行
  • @return from,offset 开始行数,偏移量
  • 2020/05/15
  • gz

func GetRandomNumber

func GetRandomNumber(length int) string

生成随机数字

func GetRandomString

func GetRandomString(length int) string

生成随机字符串

func IoUsage

func IoUsage() map[string]string
  • disk usage of path/disk
func DiskUsage(path string) map[string]string {
	mDisk := make(map[string]string)
	sFs := syscall.Statfs_t{}
	Err := syscall.Statfs(path, &sFs)
	if Err != nil {
		log.Println("ERROR", "170060|查询磁盘使用情况出错", Err.Error())
		return mDisk
	}
	All := sFs.Blocks * uint64(sFs.Bsize) / 1024 / 1024
	Free := sFs.Bfree * uint64(sFs.Bsize) / 1024 / 1024
	mDisk["All"] = strconv.FormatUint(All, 10)
	mDisk["Free"] = strconv.FormatUint(Free, 10)
	mDisk["Used"] = strconv.FormatUint((All - Free), 10)
	return mDisk
}
func MemStat() map[string]string {
	//系统占用,仅linux/mac下有效
	//system memory usage
	mMem := make(map[string]string)
	sysInfo := new(syscall.Sysinfo_t)
	Err := syscall.Sysinfo(sysInfo)
	if Err == nil {
		All := sysInfo.Totalram / 1024 / 1024
		Free := sysInfo.Freeram / 1024 / 1024
		Swap := sysInfo.Totalswap / 1024 / 1024
		SwapFree := sysInfo.Freeswap / 1024 / 1024
		mMem["All"] = strconv.FormatUint(All, 10)   //* uint64(syscall.Getpagesize())
		mMem["Free"] = strconv.FormatUint(Free, 10) //* uint64(syscall.Getpagesize())
		mMem["Used"] = strconv.FormatUint(All-Free, 10)
		mMem["Swap"] = strconv.FormatUint(Swap, 10)
		mMem["SwapFree"] = strconv.FormatUint(SwapFree, 10)
		mMem["SwapUsed"] = strconv.FormatUint(Swap-SwapFree, 10)
		day := sysInfo.Uptime / 86400
		hour := sysInfo.Uptime % 86400 / 3600
		minute := sysInfo.Uptime % 86400 % 3600 / 60
		tTime := time.Now().Unix() - sysInfo.Uptime
		tNow := time.Unix(tTime, 10)
		mMem["StartTime"] = tNow.Format("2006") + "-" + tNow.Format("01") + "-" + tNow.Format("02") + " " + tNow.Format("15") + ":" + tNow.Format("04") + ":" + tNow.Format("05")
		mMem["Runtime"] = strconv.FormatInt(day, 10) + "天" + strconv.FormatInt(hour, 10) + "小时" + strconv.FormatInt(minute, 10) + "分钟"

	} else {
		log.Println("ERROR", "170060|查询内存使用情况出错", Err.Error())
	}
	return mMem
}

*

  • IO读写

func IsInStringArray

func IsInStringArray(arr []string, str string) bool

*

  • 是否存在在字符切片中

func LoadAverage

func LoadAverage() map[string]string

*

*系统负载1 5 10 分钟

func MergeStringMap

func MergeStringMap(x, y map[string]string) map[string]string

func NetBytes

func NetBytes(Iface string) []string

*

*网卡实时流量

func NetUsage

func NetUsage() []interface{}

*

*网卡使用情况

func NewUUID

func NewUUID() string

Simple call

func ParamsString

func ParamsString(param string) string

*

  • 处理传递的参数
  • @param param
  • @return
  • 2020/05/15
  • gz

func ParseUUID

func ParseUUID(uuid string) ([]byte, error)

func PutNetConfig

func PutNetConfig(mString map[string]string) error

*

*修改网络配置

func StrFirstToUpper

func StrFirstToUpper(str string) string

*

  • 字符串转大驼峰 ios_bbbbbbbb -> IosBbbbbbbbb

func StringJoin

func StringJoin(s ...string) string

* 连接多个字符串 * 2019/05/05

func ToFloat64

func ToFloat64(v interface{}) (float64, error)

func ToInt

func ToInt(inter interface{}) int

func ToInt64

func ToInt64(inter interface{}) int64

func ToMapStringArray

func ToMapStringArray(x interface{}) ([]map[string]string, error)

*

  • 转换为map string数组
  • 2021/1/5
  • gz

func ToStr

func ToStr(v interface{}) string

func ToString

func ToString(v interface{}) string

func UrlJoin

func UrlJoin(host, url string) string

* 连接url * 2019/05/05

Types

type Validate

type Validate struct {
	Data  []interface{}
	Title []string
	Rule  []string //多个规则使用逗号(,)隔开
}

func (*Validate) Check

func (v *Validate) Check() error

Jump to

Keyboard shortcuts

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