package idgenerator import ( "errors" "github.com/bwmarrin/snowflake" ) // With default settings, this snowflake generator should be sufficiently fast enough // on most systems to generate 4096 unique ID's per millisecond. This is the maximum // that the snowflake ID format supports. That is, around 243-244 nanoseconds per operation. // 业务node, node ∈ [0, 1023] const ( NodeMin = 0 // 最小node 包括 NodeMax = 1023 // 最大node 包括 ) const ( _ = iota NodeMaterial // node 素材(商品) NodeCatalog // node 分类 NodeOrder // node 订单 NodeBanner // node banner NodeLogin // node login NodeToken // node token NodeAccount // node account NodeVeriCode // node vericode NodeMember // node 用户id NodeProduct // node 商品 NodeMoment // node 动态 NodeFootPrint // node 足迹 NodeThumbsUp // node 点赞 NodeAccountRelation // node 用户关系 NodeStreamer // node 主播 NodeFeedback // node 意见反馈 NodeCallHistory // node 通话记录 NodeStreamerLink // node 主播链接 NodeUserWxAddCheck // node 用户微信添加审核 NodeRealNameAuthentication // node 实名认证 NodeContactCustomerService // node 联系客服 NodeImageAudit // node 图像审核 NodeCoinOrder // node 金币订单 NodeImageAuditTask // node 图像审核任务 NodeTextAudit // node 文字审核 NodeTextAuditTask // node 文字审核任务 NodeDailyStatement // node 每日报表表 NodeWithdrawOrderId // node 提现订单 NodeAppConfig // node 应用配置表 NodeAccountCancellation // node 账户注销 NodeWxpayRefund // node 微信支付退款 NodeZoneMomentThumbsUp // node 私密圈动态点赞 NodeZoneSession // node 空间对话表 NodeZoneThirdPartner // node 空间代运营表 NodeDailyStatementZoneInfo // node 空间相关每日报表 NodeYeepayRefund // node 易宝支付退款 NodeWorkerId // node 用户职业者id映射表 NodeSingleDistributeHis // node 慧用工下发打款历史表 NodeEmail // node 电子邮件表 NodeNotification // node 系统通知表 ) func GenIdInt64(node int64) (int64, error) { if node < NodeMin || node > NodeMax { return -1, errors.New("node number must include [0, 1023]") } n, err := snowflake.NewNode(node) if err != nil { return -1, err } return n.Generate().Int64(), nil } func GenIdString(node int64) (string, error) { if node < NodeMin || node > NodeMax { return "", errors.New("node number must include [0, 1023]") } n, err := snowflake.NewNode(node) if err != nil { return "", err } return n.Generate().String(), nil } // 商品 func GenProductId() string { id, _ := GenIdString(NodeProduct) return id } // 订单 func GenOrderId() string { id, _ := GenIdString(NodeOrder) return id } // 金币订单 func GenCoinOrderId() string { id, _ := GenIdString(NodeCoinOrder) return id } // banner func GenBannerId() int64 { id, _ := GenIdInt64(NodeBanner) return id } // login func GenLoginId() int64 { id, _ := GenIdInt64(NodeLogin) return id } // token func GenTokenId() int64 { id, _ := GenIdInt64(NodeToken) return id } // account func GenAccountId() int64 { id, _ := GenIdInt64(NodeAccount) return id } // vericode func GenVeriCodeId() int64 { id, _ := GenIdInt64(NodeVeriCode) return id } // catalog func GenCatalogId() int64 { id, _ := GenIdInt64(NodeCatalog) return id } // moment func GenMomentId() int64 { id, _ := GenIdInt64(NodeMoment) return id } // footprint func GenFootPrintId() int64 { id, _ := GenIdInt64(NodeFootPrint) return id } // thumbs_up func GenThumbsUpId() int64 { id, _ := GenIdInt64(NodeThumbsUp) return id } // account_relation func GenAccountRelationId() int64 { id, _ := GenIdInt64(NodeAccountRelation) return id } // streamer func GenStreamerId() int64 { id, _ := GenIdInt64(NodeStreamer) return id } // feedback func GenFeedbackId() int64 { id, _ := GenIdInt64(NodeFeedback) return id } // callhistory func GenCallHistoryId() int64 { id, _ := GenIdInt64(NodeCallHistory) return id } // streamerlink func GenStreamerLinkId() int64 { id, _ := GenIdInt64(NodeStreamerLink) return id } // userwxaddcheck func GenUserWxAddCheckId() int64 { id, _ := GenIdInt64(NodeUserWxAddCheck) return id } // realname_authentication func GenRealNameAuthenticationId() int64 { id, _ := GenIdInt64(NodeRealNameAuthentication) return id } // contact_customer_service func GenContactCustomerServiceId() int64 { id, _ := GenIdInt64(NodeContactCustomerService) return id } // daily_statement func GenDailyStatementId() int64 { id, _ := GenIdInt64(NodeDailyStatement) return id } // withdraw_order func GenWithdrawOrderId() string { id, _ := GenIdString(NodeWithdrawOrderId) return id } // app_config func GenAppConfigId() int64 { id, _ := GenIdInt64(NodeAppConfig) return id } // account_cancellation func GenAccountCancellationId() int64 { id, _ := GenIdInt64(NodeAccountCancellation) return id } // wxpay refund func GenWxpayRefundId() string { id, _ := GenIdString(NodeWxpayRefund) return id } // zone_moment_thumbs_up func GenZoneMomentThumbsUpId() int64 { id, _ := GenIdInt64(NodeZoneMomentThumbsUp) return id } // zonesession func GenZoneSessionId() int64 { id, _ := GenIdInt64(NodeZoneSession) return id } // zone_third_partner func GenZoneThirdPartnerId() int64 { id, _ := GenIdInt64(NodeZoneThirdPartner) return id } // daily_statement_zone_info func GenDailyStatementZoneInfoId() int64 { id, _ := GenIdInt64(NodeDailyStatementZoneInfo) return id } // yeepay refund func GenYeepayRefundId() string { id, _ := GenIdString(NodeYeepayRefund) return id } // worker_id func GenWorkerIdId() int64 { id, _ := GenIdInt64(NodeWorkerId) return id } // single_distribute_his func GenSingleDistributeHisId() string { id, _ := GenIdString(NodeSingleDistributeHis) return id } // email func GenEmailId() int64 { id, _ := GenIdInt64(NodeEmail) return id } // notification func GenNotificationId() int64 { id, _ := GenIdInt64(NodeNotification) return id }