utils

package
v2.0.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	BASE32                = "0123456789bcdefghjkmnpqrstuvwxyz"
	MAX_LATITUDE  float64 = 90
	MIN_LATITUDE  float64 = -90
	MAX_LONGITUDE float64 = 180
	MIN_LONGITUDE float64 = -180
)

Variables

View Source
var (
	ErrNotBranch = errors.New("keys are not branch") // A node in the path specified by keys is not branch.
	ErrNotLeaf   = errors.New("keys are not leaf")   // A node in the path specified by keys is not leaf.
	ErrNotExist  = errors.New("value is not exist")  // No value is present
)

Define error code for NestedMap.

Functions

func Byte2string

func Byte2string(b []byte) string

from fasthttp

func Contains

func Contains(leftList []interface{}, rightList []interface{}) bool

func ConvertFeatures

func ConvertFeatures(features map[string]interface{}) map[string]*FeatureInfo

func CostTime

func CostTime(start time.Time) int64

func Equal

func Equal(l interface{}, r interface{}) bool

func EvalDate

func EvalDate(expression string) (string, bool)

func FormatDate

func FormatDate(date time.Time, dateStyle string) string

FormatDate 日期转字符串

func GetClientIp

func GetClientIp() (string, error)

func GetExperimentParamByPath

func GetExperimentParamByPath(params model.LayerParams, path string, defaultValue interface{}) interface{}

func GetTypeOf

func GetTypeOf(value interface{}) string

func GetValueByType

func GetValueByType(value interface{}, vtype string) interface{}

func Greater

func Greater(l interface{}, r interface{}) bool

func GreaterEqual

func GreaterEqual(l interface{}, r interface{}) bool

func HashValue

func HashValue(hashKey string) uint64

func In

func In(l interface{}, r interface{}) bool

func IndexOf

func IndexOf(a []string, e string) int

func IntContains

func IntContains(leftList []int, rightList []int) bool

func IsDateExpression

func IsDateExpression(expression string) bool

func IsNil

func IsNil(i interface{}) bool

func Less

func Less(l interface{}, r interface{}) bool

func LessEqual

func LessEqual(l interface{}, r interface{}) bool

func Ln

func Ln(n float64) float64

func MaxInt

func MaxInt(x, y int) int

func Md5

func Md5(msg string) string

func MinInt

func MinInt(x, y int) int

func MinInt64

func MinInt64(x, y int64) int64

func NotEqual

func NotEqual(l interface{}, r interface{}) bool

func Sigmoid

func Sigmoid(x float64) float64

func String2byte

func String2byte(s string) (b []byte)

func StringContains

func StringContains(leftList []string, rightList []string) bool

func ToBool

func ToBool(i interface{}, defaultVal bool) bool

func ToFloat

func ToFloat(i interface{}, defaultVal float64) float64

func ToInt

func ToInt(i interface{}, defaultVal int) int

func ToInt64

func ToInt64(i interface{}, defaultVal int64) int64

func ToString

func ToString(i interface{}, defaultVal string) string

func UUID

func UUID() string

func UniqueStrings

func UniqueStrings(strSlice []string) []string

Types

type Box

type Box struct {
	MinLat, MaxLat float64 // 纬度
	MinLng, MaxLng float64 // 经度
}

Box geohash的精度与其长度成正比 每个点的geohash值实际上代表了一个区域,这个区域的大小与geohash的精度成反比 坐标点的格式为(纬度,经度) 将这个区域用一个矩形表示

func GeoHashEncode

func GeoHashEncode(latitude, longitude float64, precision int) (string, *Box)

GeoHashEncode 输入值:纬度,经度,精度(geohash的长度) 返回geohash, 以及该点所在的区域

func (*Box) Height

func (this *Box) Height() float64

func (*Box) Width

func (this *Box) Width() float64

type FeatureInfo

type FeatureInfo struct {
	Value interface{} `json:"value"`
	Type  string      `json:"type"`
}

type NestedMap

type NestedMap sync.Map

NestedMap is is a map that can be nested infinitely, as shown below:

               /->key1:value1
/->branch_map1 -->key2:value2

root_map \->key3:value3

\->branch_map2 -->branch_map3 -->key4:value4
                              \->key5:value5

NestedMap key type is ...interface{}, it can only be in the following formats: 1. "a", 2, "c" or, 2. [1, "b", 3] But it cannot be in the following format: 1. "a", ["b", "c"] or, 2. 1, [2, 3] or, 3. "a", [2, 3] or, 4. 1, ["b", "c"]

func (*NestedMap) Delete

func (nm *NestedMap) Delete(keys ...interface{}) error

Delete deletes the value for keys.

func (*NestedMap) Load

func (nm *NestedMap) Load(keys ...interface{}) (interface{}, error)

Load returns the value stored in the map for a key, or nil if no value is present.

func (*NestedMap) LoadOrStore

func (nm *NestedMap) LoadOrStore(value interface{}, keys ...interface{}) (actual interface{}, loaded bool, err error)

LoadOrStore returns the existing value for the keys if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.

func (*NestedMap) Range

func (nm *NestedMap) Range(f func(keys []interface{}, value interface{}) bool, keys ...interface{}) error

Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.

func (*NestedMap) Store

func (nm *NestedMap) Store(value interface{}, keys ...interface{}) error

Store sets the value for keys.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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