utils

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: AGPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StringType = "string"
	NumberType = "number"
	BoolType   = "bool"
	Unknown    = "unknown"
)
View Source
const (
	Seconds = "seconds"
	Minutes = "minutes"
	Hours   = "hours"
)

Variables

View Source
var (
	APPLICATION_CONFIG_PATH = "conf/application.yml"
	TEMPLATE_JSON_PATH      = "conf/template.json"
	IPDB_PATH               = "conf/ipdata.dat"
	TA_JS_PATH              = "static/ta.js"
	TRANSLATE_PATH          = "conf/translate.yml"
)
View Source
var (
	// ErrInvalidIP invalid ip format
	ErrInvalidIP = errors.New("invalid ip format")
)

Functions

func ConvertArrToMap

func ConvertArrToMap(list []string) map[string]bool

func ConvertBool

func ConvertBool(obj interface{}) (bool, bool)

func ConvertDataType

func ConvertDataType(obj interface{}, dataType string) (interface{}, error)

func ConvertFloat64

func ConvertFloat64(obj interface{}) (float64, bool)

func ConvertInt64

func ConvertInt64(obj interface{}) (int64, bool)

func ConvertMSToUnit

func ConvertMSToUnit(t int64) (value int64, unit string)

func ConvertString

func ConvertString(obj interface{}) (string, bool)

func ConvertStringArr

func ConvertStringArr(obj interface{}) ([]string, bool)

ConvertStringArr interface转字符串数组

func ConvertStringArrToInterfaceArr

func ConvertStringArrToInterfaceArr(list []string) []interface{}

func ConvertStringToMS

func ConvertStringToMS(value string, now int64) (int64, error)

func ConvertStructToMap

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

func ConvertTimeToMS

func ConvertTimeToMS(t time.Time) int64

func ConvertUint64

func ConvertUint64(obj interface{}) (uint64, bool)

func ConvertUnitToMS

func ConvertUnitToMS(value int64, unit string) int64

func GetMD5Base64

func GetMD5Base64(bytes []byte) string

func GetMD5Base64WithLegth

func GetMD5Base64WithLegth(bytes []byte, maxLength int) string

func GetMapValue

func GetMapValue(key string, data map[string]interface{}) interface{}

func GetMapValueArr

func GetMapValueArr(m map[string]interface{}, key string) ([]interface{}, bool)

func GetMapValueBool

func GetMapValueBool(m map[string]interface{}, key string) (bool, bool)

func GetMapValueFloat64

func GetMapValueFloat64(m map[string]interface{}, key string) (float64, bool)

func GetMapValueInt64

func GetMapValueInt64(m map[string]interface{}, key string) (int64, bool)

func GetMapValueMap

func GetMapValueMap(m map[string]interface{}, key string) (map[string]interface{}, bool)

func GetMapValueString

func GetMapValueString(m map[string]interface{}, key string) (string, bool)

func GetMapValueUint64

func GetMapValueUint64(m map[string]interface{}, key string) (uint64, bool)

func GetPath

func GetPath(s string) string

GetPath .

func IsMobile

func IsMobile(ua string) bool

IsMobile .

func IsNil

func IsNil(val interface{}) bool

func NewContextWithHeader added in v1.1.0

func NewContextWithHeader(ctx context.Context) context.Context

func ParseInt64

func ParseInt64(value string, def int64) int64

ParseInt64 .

func ParseInt64WithRadix

func ParseInt64WithRadix(value string, def int64, radix int) int64

ParseInt64WithRadix .

func RandomString

func RandomString(n int) string

func ReadLine

func ReadLine(fileName string, handler func(string)) error

func ReplaceNumber

func ReplaceNumber(path string) string

ReplaceNumber .

func StringToBytes

func StringToBytes(s string) []byte

func TypeOf

func TypeOf(obj interface{}) string

func UUID

func UUID() (string, error)

Types

type Duration

type Duration time.Duration

func (Duration) Duration

func (d Duration) Duration() time.Duration

func (Duration) FormatDuration

func (d Duration) FormatDuration(precision int) (string, error)

Keep the specified decimal places.

func (Duration) MarshalYAML

func (d Duration) MarshalYAML() (interface{}, error)

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error

type LocationInfo

type LocationInfo struct {
	Country string
	Region  string
	City    string
	Isp     string
}

LocationInfo .

type Locator

type Locator struct {
	// contains filtered or unexported fields
}

Locator .

func NewLocator

func NewLocator(dataFile string) (loc *Locator, err error)

NewLocator .

func NewLocatorWithData

func NewLocatorWithData(data []byte) (loc *Locator)

NewLocatorWithData .

func (*Locator) Find

func (loc *Locator) Find(ipstr string) (*LocationInfo, error)

Find .

func (*Locator) FindByUint

func (loc *Locator) FindByUint(ip uint32) (*LocationInfo, error)

FindByUint .

Jump to

Keyboard shortcuts

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