Documentation ¶
Index ¶
- Constants
- Variables
- func CheckError(err error, errDesc string, errInfo interface{})
- func CheckErrorWithPanic(err error, errDesc string, errInfo interface{})
- func CreateShutdownScript(srvName string) error
- func DeleteOldLogFiles(logsDir string, numDaysAgo, hour, minute int)
- func FormatStreamUrl(streamUrl string) (newStreamUrl string)
- func GenerateRandomString(length int) string
- func GetCurTime10bit() (now time.Time, ts int64)
- func GetCurTime13bit() (now time.Time, ts int64)
- func GetCurTimeStr() (nowStr string)
- func GetDelayCloseTask(recordVideoDuration uint8) int
- func GetDeleteOldRecord(recordVideoDuration uint8) int
- func GetDirAllFiles(dirPath string) (err error, fileNames []string)
- func GetDirAllFilesWithoutExt(dirPath string) (err error, fileNames []string)
- func GetMergeVideoTimeWait(recordVideoDuration uint8) int
- func GetTaskIntervalTime(recordVideoDuration uint8) int
- func GetUrlPrefix(rawURL string) (protocol, host, streamPath string)
- func GetYamlConf(cnfPath string, configStruct interface{})
- func HostIpReplace(oldHost, sourceIp string) (newHost string)
- func InitGatewayConn(confPath string) (mnc conn.MinioClient, sqlc conn.SqlClient, edc conn.EtcdClient, err error)
- func InitPredictConn(confPath string) (edc conn.EtcdClient, err error)
- func InitScheduleConn(confPath string) (mnc conn.MinioClient, ntc conn.NatsClient, edc conn.EtcdClient, err error)
- func InitVideoConn(confPath string) (mnc conn.MinioClient, edc conn.EtcdClient, err error)
- func ParseEmail(emailAddr string) (username, domain, tld string, err error)
- func TimeStampToTime(ts int64) time.Time
- func TimeToTimeStampInt10bit(t time.Time) int32
- func TimeToTimeStampInt6413bit(t time.Time) int64
- func TimeToTimeStampStr13bit(t time.Time) string
- func ValCarPlateNumber(carPtNmb string) (ok bool, carPlateType string)
- func ValEmailAddr(emailAddr string) (ok bool)
- func ValHttpUrl(httpUrl string) (ok bool)
- func ValIPOrDomain(ipOrDomain string) (ok bool)
- func ValIPOrDomainWithPort(ipOrDomainWithPort string) (ok bool)
- func ValNickname(nickname string, nicknameLen int) (ok bool)
- func ValPhoneNumber(phone, region string) bool
- func ValPwd(pwd string, pwdLen int) (ok bool)
- func ValUserName(uName string, uNameLen int) (ok bool)
- type CustomClaims
- type GatewayConfSt
- type GlobalBaseConfig
- type IdWorker
- type JWTInfo
- type PredictConfSt
- type ScheduleConfSt
- type VideoConfSt
Constants ¶
const ( // VideoBucketName ImageBucketName MinioRegion minio 相关 VideoBucketName = "alarm.video" ImageBucketName = "alarm.image" MinioRegion = "cn-north-1" GlobalBaseConfigKey = "global_base_config" // Default RPCCodeSuc 状态码 RPCCodeSuc = 10200 RPCCodeFailed = 10201 // Default RPCInfo rpc信息 RPCMsgSuc = "消息接收成功" RPCMsgFailed = "告警消息内容不全" RPCMsgPredictInfoFailed = "推理机信息收集不全" RPCMsgTaskCloseFailed = "任务关闭失败" RPCMsgTaskCloseOpen = "任务开启失败" RpcServicePredict = "predict" RpcServiceSchedule = "schedule" RpcServiceGateway = "gateway" RpcEtcdPredictErr = "发现etcd的predict服务失败" RpcPredictNewClientErr = "创建推理机RPC客户端失败" RpcPredictTaskOpenErr = "分配任务给推理机失败" RpcRegisterErr = "注册服务到etcd失败" RpcConnEtcdErr = "rpc kitex 连接etcd失败" RpcGateNewClientErr = "创建gateRPC客户端失败" // for gateway and video VideoPreviewUrlSplitStr = "ISSTECHVIDEOSPLIT" // AlarmInfoErr 告警消息处理 AlarmInfoErr = "推理机发送的告警信息不全" AlarmSubject = "alarm" AlarmQueue = "queue01" HttpClientTimeOut = 5 NoticeStatusDefault = 0 NoticeStatusSuc = 1 NoticeStatusFailed = 2 MinioContentImg = "image/jpeg" MinioContentVideo = "video/mp4" MinioDefaultDay = time.Hour * 24 * 7 // 七天 TaskStatusClose = 0 TaskStatusOpen = 1 //推理机状态 PredictStatusOpen = 1001 PredictStatusClose = 1002 //----------------------------正则验证相关-------------------------- // 常用国际电话号码区号 ChinaMainlandPhNumberRegion = "+86" // 中国大陆电话区号 ChinaMacauPhNumberRegion = "+853" // 中国澳门电话区号 ChinaHongKongPhNumberRegion = "+852" // 中国香港电话区号 ChinaTaiwanPhNumberRegion = "+886" // 中国台湾电话区号 MalaysiaPhNumberRegion = "+60" // 马来西亚电话区号 DubaiPhNumberRegion = "+971" // 迪拜,阿联酋 电话区号 PhilippinesPhNumberRegion = "+63" // 菲律宾电话区号 // 车牌号类型定义 包含 油车与新能源(混动+纯电) CarPlateICEType = "1" // 油车 CarPlateENVType = "2" // 新能源 // 常用正则表达式 IPOrDomainReg = `` // ip 或 域名的检测 /* 147-byte string literal not displayed */ UsernameReg = `^[a-zA-Z0-9_]{4,}$` // 登录账号 由字母、数字、下划线组成的字符串 NicknameReg = "^[\u4e00-\u9fa5a-zA-Z0-9_]{1,}$" // 昵称 由汉字、字母、数字组成 PasswordReg = `^[a-zA-Z0-9!~@#$%^&*)(_+.-={}|]{2,}$` // 登录密码 由字母、数字、特殊字符等组成 EmailAddrReg = `` // 邮件地址 /* 149-byte string literal not displayed */ ChinaMainlandIDReg = `` // 大陆身份证 支持15和18位 /* 354-byte string literal not displayed */ ChinesHkMacaoPspReg = `^[EeKkGgDdSsPpHh]\d{8}$)|(^(([Ee][a-fA-F])|([DdSsPp][Ee])|([Kk][Jj])|([Mm][Aa])|(1[45]))\d{7}$` // 香港 澳门的护照 ChinaMainlandPhNumberReg = `^[1][3-9][0-9]{9}$` // 大陆电话号码 ChinaMacauPhNumberReg = `^\d{8}$` // 中国澳门电话格式 ChinaHongKongPhNumberReg = `^[56789]\d{7}$` // 中国香港电话格式 ChinaTaiwanPhNumberReg = `^09\d{8}$` // 中国台湾电话格式 MalaysiaPhNumberReg = `^(?:(?:0[1-9]\d{2})\)?[ -]?\d{7,8})$` // 马来西亚电话格式 DubaiPhNumberReg = `^971[ -]?(?:\d{1,3})[ -]?\d{7,8}$` // 迪拜 阿联酋电话格式 PhilippinesPhNumberReg = `^63[ -]?(?:\d{2,3})[ -]?\d{7,8}$` // 菲律宾电话格式 CarPlateNumberICEReg = `` // Car Plate Number 车牌号(油车) /* 160-byte string literal not displayed */ CarPlateNumberNEVReg = `` // 车牌号,新能源 混动+纯电 /* 213-byte string literal not displayed */ GUIDOrUUIDReg = `^[a-f\d]{4}(?:[a-f\d]{4}-){4}[a-f\d]{12}$` // UUID 或 GUID )
const ( DistrictIdBits = uint(4) //区域 所占用位置 NodeIdBits = uint(9) //节点 所占位置 2的n次幂,6就是2的6次幂64个节点 DistrictIdShift = sequenceBits + NodeIdBits )
Variables ¶
Functions ¶
func CheckError ¶
func CheckErrorWithPanic ¶
func CreateShutdownScript ¶
func DeleteOldLogFiles ¶
用于删除指定天数的指定目录下的日志文件 logsDir:日志所在的目录 numDaysAgo:删除几天前的文件 hour minute:每天的几点几分执行
func FormatStreamUrl ¶
检查视频流的url,将复杂的字符替换掉,此处以大华为案例
func GetCurTime13bit ¶
GetCurTime 获取当前时间毫秒级和13位的时间戳,UTC ,数组截取时为了避免尾数四舍五入的情况
func GetDelayCloseTask ¶
获取延迟关闭任务时间 延迟关闭任务的目的:避免关闭视频流时发生告警引起视频无法录制到事件的后N秒
func GetDirAllFiles ¶
获取指定目录下所有文件名,带后缀
func GetDirAllFilesWithoutExt ¶
获取指定目录下所有文件名,将文件后缀去掉
func GetTaskIntervalTime ¶
获取关闭任务后间隔开启任务的时间 开启任务时要检查上次关闭视频流的时间,目的是:避免因为延迟关闭而导致刚开启的任务视频流被关闭 例如:视频A的任务1 在10:01:00关闭了,但实际它将在N(5)秒后关闭视频流,如果马上开启任务, 与上次关闭视频流时间小于10:01:00+5 那在05秒的时候就会关闭05秒之前开启的任务,导致任务失败
func GetUrlPrefix ¶
根据url获取protocol host:ip:port steamPath(已做唯一值处理格式为:ip+port/md5(url))
func GetYamlConf ¶
func GetYamlConf(cnfPath string, configStruct interface{})
func InitGatewayConn ¶
func InitGatewayConn(confPath string) (mnc conn.MinioClient, sqlc conn.SqlClient, edc conn.EtcdClient, err error)
func InitPredictConn ¶
func InitPredictConn(confPath string) (edc conn.EtcdClient, err error)
func InitScheduleConn ¶
func InitScheduleConn(confPath string) (mnc conn.MinioClient, ntc conn.NatsClient, edc conn.EtcdClient, err error)
func InitVideoConn ¶
func InitVideoConn(confPath string) (mnc conn.MinioClient, edc conn.EtcdClient, err error)
func ParseEmail ¶ added in v1.0.7
ParseEmail 解析邮件地址,提取用户名、二级域名、一级域名
func TimeToTimeStampInt10bit ¶
将传入的时间转为10位的int类型,多用于时间比较
func TimeToTimeStampInt6413bit ¶
将传入的时间转为13位的int64类型,多用于时间比较
func TimeToTimeStampStr13bit ¶
将时间转为13位的字符串类型,多用于日志或数据入库
func ValCarPlateNumber ¶ added in v1.0.8
ValEmailAddr 验证邮箱地址
func ValEmailAddr ¶ added in v1.0.7
ValEmailAddr 验证邮箱地址
func ValHttpUrl ¶ added in v1.0.7
“正则匹配” 常见的英文表述是 “Regular Expression Matching” 简称 “Val” ValHttpUrl 检测http核https的url,严格检测ip和域名规则,端口号严格控制在10-65535内,http url format: http[s]://1.1.1.1:8080/ass/sss
func ValIPOrDomain ¶ added in v1.0.7
ValIPOrDomain 检测ip或域名是否合规
func ValIPOrDomainWithPort ¶ added in v1.0.7
ValIPOrDomainWithPort 检测ip或域名是否合规
func ValNickname ¶ added in v1.0.7
ValNickname 用户昵称检测,昵称只支持汉字、字母、数字组成
func ValPhoneNumber ¶ added in v1.0.7
ValPhoneNumber 按区域验证电话号码是否合规
func ValUserName ¶ added in v1.0.7
ValUserName 检测用户名是否合规
Types ¶
type CustomClaims ¶
type GatewayConfSt ¶
type GatewayConfSt struct { EtcdConf model.EtcdConf `json:"etcd_conf" yaml:"etcd_conf"` SqlCnf model.SQLConf `json:"sql_cnf" yaml:"sql_cnf"` MinioCnf model.MinioConf `json:"minio_cnf" yaml:"minio_cnf"` LogCnf model.LogConf `json:"log_cnf" yaml:"log_cnf"` }
func GetGatewayConfByYml ¶
func GetGatewayConfByYml(cnfPath string) (env GatewayConfSt)
GetGatewayConfByYml 按配置文件获取配置信息
type GlobalBaseConfig ¶
type GlobalBaseConfig struct { /* 这里是详情描述 for video rtsp和rtmp 每个视频服务都会做视频转码,转码后的地址供推理端使用,多个视频服务时需要配置多个, video服务在本地配置文件中有video_id的编号,从0开始,按此id获取数组中的暴漏地址 例如:["1.1.1.1:1935","1.1.1.1:1935","1.1.1.2:1935"] 配置文件中video_id=0将匹配到1.1.1.1:1935 H5LiveAddress: 给h5页面访问的视频地址,逻辑同上,此地址是客户端所在机器能访问到的,如果是代理后 的ip:port 则注意代理配置内容关系是 video真实ip:port代理到nginx外网ip ,我们配置的是nginx外网ip:port MinioPreviewAddress: 默认写的是minio服务所在ip:port 如果是代理后的ip:port 则注意代理配置内容关系是 minio真实ip:port代理到nginx外网ip,我们配置的是nginx外网ip:port RecordVideoDuration: 录制的视频时长,单位秒,默认10s,取值范围10-60s FfmpegBinPath: 引用的ffmpeg命令路径 "ffmpeg_bin_path": "ffmpeg" LogFileKeepDays: 服务产生的日志文件保留天数-不包含审计日志,审计日志已入库不受影响 */ RtspExportAddress []string `json:"rtsp_export_address" yaml:"rtsp_export_address"` // 给推理端内部的rtsp地址 RtmpExportAddress []string `json:"rtmp_export_address" yaml:"rtmp_export_address"` // 给推理端内部的rtmp地址 H5LiveAddress []string `json:"h5_live_address" yaml:"h5_live_address"` // 前端页面播放直播流的地址 MinioPreviewAddress string `json:"minio_preview_address" yaml:"minio_preview_address"` // 告警图片和视频浏览地址 FfmpegBinPath string `json:"ffmpeg_bin_path" yaml:"ffmpeg_bin_path"` // 引用的ffmpeg命令路径 RecordPath string `json:"record_path" yaml:"record_path"` // 设置录制视频的路径:record/hls RecordVideoDuration uint8 `json:"record_video_duration" yaml:"record_video_duration"` // 录制的视频时长,单位秒,默认10s LogFileExpirationDays uint8 `json:"log_file_expiration_days" yaml:"log_file_expiration_days"` // 日志文件过期时间 MinioDataExpirationDays uint16 `json:"minio_data_expiration_days" yaml:"minio_data_expiration_days"` // minio中数据过期时间 TaskAlgCountLimit uint8 `json:"task_alg_count_limit" yaml:"task_alg_count_limit"` // 每个任务允许的算法个数,取值范围1-10,默认3 ThirdPartyVideoSourceType uint8 `json:"third_party_video_source_type" yaml:"third_party_video_source_type"` // 第三方视频源同步类型,0不开启,1华为,2海康 ThirdPartyAddress []string `json:"third_party_address" yaml:"third_party_address"` // 格式:"ip:port,ip:port"支持视频集群地址 ThirdPartyUserName string `json:"third_party_user_name" yaml:"third_party_user_name"` // 用户名,用于获取第三方验证token或session的 ThirdPartyUserPwd string `json:"third_party_user_pwd" yaml:"third_party_user_pwd"` // 用户密码,用于获取第三方验证token或session的 }
全局基础配置-放在etcd用于后台配置动态更新
type IdWorker ¶
type IdWorker struct {
// contains filtered or unexported fields
}
func NewIdWorker ¶
NewIdWorker 创建雪花算法对象,当前设置为17位id,支持的districtId区域(可理解为IDC机房或云区域)为2的2次幂0-3,共4个区域,NodeId范围是2的7次幂0-127共128个节点数量,8毫秒内自增id
func (*IdWorker) GetId ¶
GetId 获取id,当前设置为17位id,支持的区域为2的2次幂4个区域,nodeId范围是2的7次幂0-127共128个节点数量,8毫秒内自增id
type JWTInfo ¶
type JWTInfo struct {
SignKey []byte
}
func (*JWTInfo) RefreshToken ¶
RefreshToken 更新token
func (*JWTInfo) TokenCreate ¶
func (j *JWTInfo) TokenCreate(tokenInfo CustomClaims) (string, error)
TokenCreate 创建token
func (*JWTInfo) TokenParse ¶
func (j *JWTInfo) TokenParse(token string) (*CustomClaims, error)
TokenParse 解析token
type PredictConfSt ¶
type PredictConfSt struct { EtcdConf model.EtcdConf `json:"etcd_conf" yaml:"etcd_conf"` LogCnf model.LogConf `json:"log_cnf" yaml:"log_cnf"` }
func GetPredictConfByYml ¶
func GetPredictConfByYml(cnfPath string) (env PredictConfSt)
GetPredictConfByYml 按配置文件获取配置信息
type ScheduleConfSt ¶
type ScheduleConfSt struct { EtcdConf model.EtcdConf `json:"etcd_conf" yaml:"etcd_conf"` MinioCnf model.MinioConf `json:"minio_cnf" yaml:"minio_cnf"` LogCnf model.LogConf `json:"log_cnf" yaml:"log_cnf"` }
func GetScheduleConfByYml ¶
func GetScheduleConfByYml(cnfPath string) (env ScheduleConfSt)
GetScheduleConfByYml 按配置文件获取配置信息
type VideoConfSt ¶
type VideoConfSt struct { EtcdConf model.EtcdConf `json:"etcd_conf" yaml:"etcd_conf"` MinioCnf model.MinioConf `json:"minio_cnf" yaml:"minio_cnf"` LogCnf model.LogConf `json:"log_cnf" yaml:"log_cnf"` }
func GetVideoConfByYml ¶
func GetVideoConfByYml(cnfPath string) (env VideoConfSt)
GetVideoConfByYml 按配置文件获取配置信息