common

package
v0.0.0-...-329f2e7 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckInternalIp

func CheckInternalIp(ip string) bool

*

判断内网IP
A  10.0.0.0/8:10.0.0.0~10.255.255.255
B  172.16.0.0/12:172.16.0.0~172.31.255.255
C  192.168.0.0/16:192.168.0.0~192.168.255.255

*

func CountWeek

func CountWeek(TimeFormat string) int

获取当前日期为当月第几周

func Empty

func Empty(value interface{}) bool

判断一个数据是否为空,支持int, float, string, slice, array, map的判断

func GetFloat

func GetFloat(val interface{}) float64

通过interface{}获取小数型数据 此获取比较灵活,转换规则如下 1、如果接收数据为浮点string,则将字符串转换为浮点数 2、如果接收数据是float型,则返回float数据 3、如果接收数据是int, int32, int64型,则转义成float类型 4、返回的数据结果统一为float64

func GetInt

func GetInt(val interface{}) int

通过interface{}获取数值型数据 此获取比较灵活,转换规则如下 1、如果接收数据为浮点string,则返回浮点数的整数部分,如果是整型string,则返回整数,如果是纯字符串,则返回0 2、如果接收数据是float型,则返回float的整数部分 3、如果接收数据是int, int32, int64型,则返回int

func GetString

func GetString(val interface{}) string

通过interface{}获取字符串

func GetWeekday

func GetWeekday(TimeFormat string) string

func InList

func InList(needle interface{}, haystack interface{}) bool

判断某一个值是否在列表(支持 slice, array, map)中

func InListIndex

func InListIndex(needle interface{}, haystack interface{}) int

返回某一个值是否在列表位置(支持 slice, array, map) -1为不再列表中

func Md5String

func Md5String(str string) string

func ReadFile

func ReadFile(path string) string

*

  • 根据path读取文件中的内容,返回字符串
  • 建议使用绝对路径,例如:"./schema/search/appoint.json"

func Round

func Round(f float64, n int) float64

浮点数四舍五入,并取前几位

func StrToInt

func StrToInt(str string) int

string转int

func SubString

func SubString(str string, begin, length int) (substr string)

func ToBool

func ToBool(obj interface{}) bool

*

  • 对象转换为bool
  • 支持类型:int,float64,string,bool
  • 其他类型报错

func ToFloat

func ToFloat(obj interface{}) float64

*

  • 对象转换为float64
  • 支持类型:int,float64,string,bool(true:1;false:0)
  • 其他类型报错

func ToInt

func ToInt(obj interface{}) int

*

  • 对象转换为int
  • 支持类型:int,float64,string,bool(true:1;false:0)
  • 其他类型报错

func ToString

func ToString(obj interface{}) string

*

  • 对象转换为string
  • 支持类型:int,float64,string,bool(true:"1";false:"0")
  • 其他类型报错

Types

type Info

type Info map[string]interface{}

func ReadJson

func ReadJson(path string) Info

func (Info) Bool

func (info Info) Bool(key string) bool

func (Info) Float

func (info Info) Float(key string) float64

func (Info) Info

func (info Info) Info(key string) Info

*

  • 支持类型:Info,interface{}
  • 其他类型报错

func (Info) InfoList

func (info Info) InfoList(key string) []Info

*

  • 支持类型:[]Info,[]interface{}
  • 其他类型报错

func (Info) Int

func (info Info) Int(key string) int

func (Info) IsList

func (info Info) IsList(key string) bool

*

  • 判断指定key是否为list

func (Info) Merge

func (info Info) Merge(source Info)

*

  • 使用info中的值覆盖source

func (Info) String

func (info Info) String(key string) string

func (Info) ToString

func (info Info) ToString() string

Jump to

Keyboard shortcuts

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