common_utils

package module
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: MIT-0 Imports: 24 Imported by: 0

README

common_utils 通用工具包

支持:Elasticsearch、InfluxDB、Kafka 的操作

开发语言和版本

golang ,版本 go1.23.1

平台支持

安心云4.0

使用方式:
  1. 设置 go 环境
    set GOPRIVATE=gitea.anxinyun.cn
  2. 查询go 版本
    go list -m -versions gitea.anxinyun.cn/container/common_utils
    如若 GOPRIVATE=gitea.anxinyun.cn 生效,则会返回 common_utils 的版本信息。
    如若无版本信息返回,有可能是没有 container 的权限,也有可能环境变量设置没有生效。

异常情况处理:

  1. https://gitea.anxinyun.cn/container 访问权限,可以联系下管理员。
  2. 环境变量设置不生效
    解决方法,在GoLand工具中进行设置:
    1)打开 Settings
    2)Go > GOROOT,Download Go SDK
    3)Go > Go Modules,设置环境变量 GOPRIVATE=gitea.anxinyun.cn
依赖包管理

common_utils 如若有修改,需要同步升级 et-go

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AlarmCodeCache map[string]common_models.AlarmCode
View Source
var DeviceInfoCache map[string]common_models.DeviceInfo
View Source
var DeviceNodeCache map[string]common_models.IotaInstances
View Source
var FormulaCache map[int]common_models.Formula
View Source
var IotaDeviceCache map[string]common_models.IotaDevice
View Source
var ProtoCache map[string]common_models.Proto
View Source
var StructureCache map[int]common_models.Structure

Functions

func NewTlsConfig

func NewTlsConfig(sslPath string) *tls.Config

func ReadIP4

func ReadIP4() []string

ReadIP4 获取ipV4

func ReadIP4WithPrefix

func ReadIP4WithPrefix(prefix string) []string

ReadIP4WithPrefix ReadIP4 获取ipV4 过滤网段 prefix

func ReadIP4WithPrefixFirst

func ReadIP4WithPrefixFirst(prefix string) string

ReadIP4WithPrefixFirst 获取ipV4 过滤网段 prefix

Types

type AlarmCacheUtil

type AlarmCacheUtil struct {
	AlarmCachePerfix string

	ALARM_SOURCE_DEVICE  int
	ALARM_SOURCE_STATION int
	// contains filtered or unexported fields
}

func NewAlarmCacheUtil

func NewAlarmCacheUtil() *AlarmCacheUtil

func (*AlarmCacheUtil) Add

func (the *AlarmCacheUtil) Add(sourceType int, sourceId string, alarmTypes ...string) int64

func (*AlarmCacheUtil) Rem

func (the *AlarmCacheUtil) Rem(sourceType int, sourceId string, alarmTypes ...string) int64

type ChainedCache

type ChainedCache struct {
	LoadableChinCache *cache.LoadableCache[any]
}

func NewChainedCache

func NewChainedCache(redisAddr string) *ChainedCache

type ConfigHelper

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

func NewConfigHelper

func NewConfigHelper(redisAddr string) *ConfigHelper

func (*ConfigHelper) DeleteChainedCacheObj added in v0.0.11

func (the *ConfigHelper) DeleteChainedCacheObj(k string) error

func (*ConfigHelper) GetAggThreshold

func (the *ConfigHelper) GetAggThreshold(structId int, factorId int) (*common_models.AggThreshold, error)

func (*ConfigHelper) GetAlarmCode

func (the *ConfigHelper) GetAlarmCode(alarmCode string) (common_models.AlarmCode, error)

func (*ConfigHelper) GetCacheWindowObj

func (the *ConfigHelper) GetCacheWindowObj(key_cacheWindow string) (common_models.CacheWindow, error)

func (*ConfigHelper) GetDataUnit

func (the *ConfigHelper) GetDataUnit() ([]common_models.DataUnit, error)

func (*ConfigHelper) GetDeviceFactorProto

func (the *ConfigHelper) GetDeviceFactorProto(factorProtoId, deviceMetaId string) (common_models.DeviceFactorProto, error)

func (*ConfigHelper) GetDeviceInfo

func (the *ConfigHelper) GetDeviceInfo(deviceId string, forceUpdate bool) (*common_models.DeviceInfo, error)

func (*ConfigHelper) GetDeviceStationIds

func (the *ConfigHelper) GetDeviceStationIds(deviceId string) ([]int, error)

func (*ConfigHelper) GetDeviceStationObjs

func (the *ConfigHelper) GetDeviceStationObjs(deviceId string) ([]common_models.Station, error)

func (*ConfigHelper) GetFactorInfo

func (the *ConfigHelper) GetFactorInfo(factorId int) (common_models.Factor, error)

func (*ConfigHelper) GetFilter

func (the *ConfigHelper) GetFilter(stationId int) (common_models.Filter, error)

func (*ConfigHelper) GetFilterItem added in v0.0.11

func (the *ConfigHelper) GetFilterItem(stationId int, item string) (common_models.FilterItem, error)

func (*ConfigHelper) GetFormulaInfo

func (the *ConfigHelper) GetFormulaInfo(formulaId int) (common_models.Formula, error)

func (*ConfigHelper) GetIotaDevice

func (the *ConfigHelper) GetIotaDevice(deviceId string) (common_models.IotaDevice, error)

func (*ConfigHelper) GetIotaMeta

func (the *ConfigHelper) GetIotaMeta(deviceId string) (common_models.DeviceMeta, error)

func (*ConfigHelper) GetIotaScheme

func (the *ConfigHelper) GetIotaScheme(dimensionId string) (common_models.IotaScheme, error)

func (*ConfigHelper) GetProto

func (the *ConfigHelper) GetProto(protoCode string) (common_models.Proto, error)

func (*ConfigHelper) GetStationCorrGroups

func (the *ConfigHelper) GetStationCorrGroups(stationId int) ([]common_models.StationGroup, error)

func (*ConfigHelper) GetStationGroup

func (the *ConfigHelper) GetStationGroup(groupId int) (common_models.StationGroup, error)

func (*ConfigHelper) GetStationGroupInfo

func (the *ConfigHelper) GetStationGroupInfo(stationId int) (common_models.StationGroupInfo, error)

func (*ConfigHelper) GetStationInfo

func (the *ConfigHelper) GetStationInfo(stationId int) (common_models.StationInfo, error)

func (*ConfigHelper) GetStationThreshold

func (the *ConfigHelper) GetStationThreshold(stationId int) (*common_models.Threshold, error)

func (*ConfigHelper) GetStations

func (the *ConfigHelper) GetStations(stationIds ...int) ([]common_models.Station, error)

func (*ConfigHelper) GetStructure added in v0.0.8

func (the *ConfigHelper) GetStructure(structId int) (common_models.Structure, error)

func (*ConfigHelper) GetSubDeviceAll

func (the *ConfigHelper) GetSubDeviceAll(deviceId, thingId string) (subDeviceIds []string)

func (*ConfigHelper) GetSubDeviceNext

func (the *ConfigHelper) GetSubDeviceNext(deviceId, thingId string) (subDeviceIds []string)

获取指定设备节点下的级联设备(递归)(不包含当前设备节点)

func (*ConfigHelper) GetThingStruct

func (the *ConfigHelper) GetThingStruct(deviceId string) (common_models.ThingStruct, error)

func (*ConfigHelper) SAddAlarm

func (the *ConfigHelper) SAddAlarm(key string, alarmTypes ...string) int64

SAddAlarm 添加Alarm缓存

func (*ConfigHelper) SRemAlarm

func (the *ConfigHelper) SRemAlarm(key string, alarmTypes ...string) int64

func (*ConfigHelper) SetAggThreshold

func (the *ConfigHelper) SetAggThreshold(structId int, factorId int, threshold common_models.AggThreshold) error

func (*ConfigHelper) SetChainedCacheObj

func (the *ConfigHelper) SetChainedCacheObj(k string, obj any) error

func (*ConfigHelper) SetChainedCacheObjWithExpiration

func (the *ConfigHelper) SetChainedCacheObjWithExpiration(k string, obj any, duration time.Duration) error

func (*ConfigHelper) SetDeviceStationObjs

func (the *ConfigHelper) SetDeviceStationObjs(deviceId string, stations common_models.StationArrayObj) error

func (*ConfigHelper) SetFactorInfo

func (the *ConfigHelper) SetFactorInfo(factorId int, factor common_models.Factor) error

func (*ConfigHelper) SetIotaScheme

func (the *ConfigHelper) SetIotaScheme(dimensionId string, scheme common_models.IotaScheme) error

RedisKey.Scheme

func (*ConfigHelper) SetStationCorrGroup

func (the *ConfigHelper) SetStationCorrGroup(stationId int, groupIds []int) error

RedisKey.station_corr_group

func (*ConfigHelper) SetStationGroup

func (the *ConfigHelper) SetStationGroup(groupId int, group common_models.StationGroup) error

RedisKey.group

func (*ConfigHelper) SetStationGroupInfo

func (the *ConfigHelper) SetStationGroupInfo(stationId int, info common_models.StationGroupInfo) error

RedisKey.station_group

func (*ConfigHelper) SetStationInfo

func (the *ConfigHelper) SetStationInfo(stationId int, station common_models.StationInfo) error

func (*ConfigHelper) SetStationThreshold

func (the *ConfigHelper) SetStationThreshold(stationId int, threshold common_models.Threshold) error

func (*ConfigHelper) StartUpdateDeviceInfo added in v0.0.14

func (the *ConfigHelper) StartUpdateDeviceInfo(interval time.Duration, batchSize int)

定时更新设备信息

type MqttHelper

type MqttHelper struct {
	Host     string
	Port     int
	ClientId string
	UserName string
	Password string
	// contains filtered or unexported fields
}

func NewMqttHelper

func NewMqttHelper(host string, port int, clientId string, userName string, password string, isSSL bool, caPtah ...string) *MqttHelper

func (*MqttHelper) Initial

func (the *MqttHelper) Initial()

func (*MqttHelper) InitialWithSSL

func (the *MqttHelper) InitialWithSSL(caPath string)

func (*MqttHelper) Publish

func (the *MqttHelper) Publish(topic string, messageBytes []byte)

func (*MqttHelper) Subscribe

func (the *MqttHelper) Subscribe(topic string, myCallback func(topic string, callMsg string))

type RedisHelper

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

func NewRedisHelper

func NewRedisHelper(master string, address ...string) *RedisHelper

func (*RedisHelper) Get

func (the *RedisHelper) Get(key string) string

func (*RedisHelper) GetLRange

func (the *RedisHelper) GetLRange(keys string, addr any) error

func (*RedisHelper) GetObj

func (the *RedisHelper) GetObj(keys string, addr any) error

func (*RedisHelper) HMGetObj

func (the *RedisHelper) HMGetObj(addr any, key, field string) error

func (*RedisHelper) InitialCluster

func (the *RedisHelper) InitialCluster(master string, address ...string)

func (*RedisHelper) InitialCluster_old added in v0.0.13

func (the *RedisHelper) InitialCluster_old(master string, address ...string)

func (*RedisHelper) MGetObj

func (the *RedisHelper) MGetObj(addr any, keys ...string) error

func (*RedisHelper) SAdd

func (the *RedisHelper) SAdd(key string, members ...string) int64

func (*RedisHelper) SRem

func (the *RedisHelper) SRem(key string, members ...string) int64

func (*RedisHelper) SetObj

func (the *RedisHelper) SetObj(keys string, obj any) error

type UnitHelper

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

func NewUnitHelper

func NewUnitHelper(configHelper *ConfigHelper) *UnitHelper

func NewUnitHelperWithConfig

func NewUnitHelperWithConfig(configHelper *ConfigHelper) *UnitHelper

func (*UnitHelper) GetUnitTransK

func (the *UnitHelper) GetUnitTransK(from, to string) float64

Directories

Path Synopsis
storage

Jump to

Keyboard shortcuts

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