当前位置: 首页 > news >正文

备案网站名称怎么改小影wordpress

备案网站名称怎么改,小影wordpress,外贸平台有哪些能直接联系老板的,北京最新消息今天新增病例ObjectID介绍 MongoDB中的ObjectId是一种特殊的12字节 BSON 类型数据#xff0c;用于为主文档提供唯一的标识符#xff0c;默认情况下作为 _id 字段的默认值出现在每一个MongoDB集合中的文档中。以下是ObjectId的具体组成#xff1a; 1. 时间戳#xff08;Timestamp… ObjectID介绍 MongoDB中的ObjectId是一种特殊的12字节 BSON 类型数据用于为主文档提供唯一的标识符默认情况下作为 _id 字段的默认值出现在每一个MongoDB集合中的文档中。以下是ObjectId的具体组成 1. 时间戳Timestamp 前4个字节32位表示创建该ObjectId时的Unix时间戳精确到秒从1970年1月1日UTC时间零点开始计算这使得ObjectId具有一定程度的时间有序性。 2. 机器标识符Machine ID 接下来的3个字节24位代表了生成此ObjectId的机器主机的唯一标识符。这个标识符通常是基于主机的网络接口地址哈希得到的目的是确保不同主机生成的ObjectId是不同的。 3. 进程标识符PID 旧版描述中提到的是进程ID但在MongoDB较新版本中已不再使用在某些早期的描述中提及2个字节代表进程ID不过实际上MongoDB并不使用进程ID来生成ObjectId以避免因为PID重用导致的冲突。现在这部分数据通常用于其他目的以保证全局唯一性。 4. 计数器Counter 最后的3个字节24位是一个自增计数器在同一台机器同一秒内生成的ObjectId会通过这个计数器递增来确保唯一性。计数器在一个秒内是从一个随机数开始递增的这样即使在同一秒内创建多个ObjectId也能保证在单机上的唯一性。 因此ObjectId的设计可以确保在分布式的环境下每个文档都能拥有一个全局唯一的标识符同时也包含了时间信息这对于很多应用场景来说非常有用比如排序、索引和逻辑处理。 ObjectID使用 分布式系统需要全局唯一ID且有序的可以考虑ObjectID。 UUID太长了且是无序的。感觉不太好ObjectID算是个还可以的选择。当然还有很多其它方案。 Go项目在Mongodb的驱动包里有一个文件是objectid.go有写好ObjectID生成算法。如果项目只要一个算法没必要引入完整的包可以直接把这个文件拷贝出来。 内容如下 package hobjectidimport (crypto/randencodingencoding/binaryencoding/hexencoding/jsonerrorsfmtiosync/atomictime )// 代码来自 https://github.com/mongodb/mongo-go-driver/blob/v1/bson/primitive/objectid.go// ErrInvalidHex indicates that a hex string cannot be converted to an ObjectID. var ErrInvalidHex errors.New(the provided hex string is not a valid ObjectID)// ObjectID is the BSON ObjectID type. type ObjectID [12]byte// NilObjectID is the zero value for ObjectID. var NilObjectID ObjectIDvar objectIDCounter readRandomUint32() var processUnique processUniqueBytes()var _ encoding.TextMarshaler ObjectID{} var _ encoding.TextUnmarshaler ObjectID{}// NewObjectID generates a new ObjectID. func NewObjectID() ObjectID {return NewObjectIDFromTimestamp(time.Now()) }// NewObjectIDFromTimestamp generates a new ObjectID based on the given time. func NewObjectIDFromTimestamp(timestamp time.Time) ObjectID {var b [12]bytebinary.BigEndian.PutUint32(b[0:4], uint32(timestamp.Unix()))copy(b[4:9], processUnique[:])putUint24(b[9:12], atomic.AddUint32(objectIDCounter, 1))return b }// Timestamp extracts the time part of the ObjectId. func (id ObjectID) Timestamp() time.Time {unixSecs : binary.BigEndian.Uint32(id[0:4])return time.Unix(int64(unixSecs), 0).UTC() }// Hex returns the hex encoding of the ObjectID as a string. func (id ObjectID) Hex() string {var buf [24]bytehex.Encode(buf[:], id[:])return string(buf[:]) }func (id ObjectID) String() string {return fmt.Sprintf(ObjectID(%q), id.Hex()) }// IsZero returns true if id is the empty ObjectID. func (id ObjectID) IsZero() bool {return id NilObjectID }// ObjectIDFromHex creates a new ObjectID from a hex string. It returns an error if the hex string is not a // valid ObjectID. func ObjectIDFromHex(s string) (ObjectID, error) {if len(s) ! 24 {return NilObjectID, ErrInvalidHex}var oid [12]byte_, err : hex.Decode(oid[:], []byte(s))if err ! nil {return NilObjectID, err}return oid, nil }// IsValidObjectID returns true if the provided hex string represents a valid ObjectID and false if not. // // Deprecated: Use ObjectIDFromHex and check the error instead. func IsValidObjectID(s string) bool {_, err : ObjectIDFromHex(s)return err nil }// MarshalText returns the ObjectID as UTF-8-encoded text. Implementing this allows us to use ObjectID // as a map key when marshalling JSON. See https://pkg.go.dev/encoding#TextMarshaler func (id ObjectID) MarshalText() ([]byte, error) {return []byte(id.Hex()), nil }// UnmarshalText populates the byte slice with the ObjectID. Implementing this allows us to use ObjectID // as a map key when unmarshalling JSON. See https://pkg.go.dev/encoding#TextUnmarshaler func (id *ObjectID) UnmarshalText(b []byte) error {oid, err : ObjectIDFromHex(string(b))if err ! nil {return err}*id oidreturn nil }// MarshalJSON returns the ObjectID as a string func (id ObjectID) MarshalJSON() ([]byte, error) {return json.Marshal(id.Hex()) }// UnmarshalJSON populates the byte slice with the ObjectID. If the byte slice is 24 bytes long, it // will be populated with the hex representation of the ObjectID. If the byte slice is twelve bytes // long, it will be populated with the BSON representation of the ObjectID. This method also accepts empty strings and // decodes them as NilObjectID. For any other inputs, an error will be returned. func (id *ObjectID) UnmarshalJSON(b []byte) error {// Ignore null to keep parity with the standard library. Decoding a JSON null into a non-pointer ObjectID field// will leave the field unchanged. For pointer values, encoding/json will set the pointer to nil and will not// enter the UnmarshalJSON hook.if string(b) null {return nil}var err errorswitch len(b) {case 12:copy(id[:], b)default:// Extended JSONvar res interface{}err : json.Unmarshal(b, res)if err ! nil {return err}str, ok : res.(string)if !ok {m, ok : res.(map[string]interface{})if !ok {return errors.New(not an extended JSON ObjectID)}oid, ok : m[$oid]if !ok {return errors.New(not an extended JSON ObjectID)}str, ok oid.(string)if !ok {return errors.New(not an extended JSON ObjectID)}}// An empty string is not a valid ObjectID, but we treat it as a special value that decodes as NilObjectID.if len(str) 0 {copy(id[:], NilObjectID[:])return nil}if len(str) ! 24 {return fmt.Errorf(cannot unmarshal into an ObjectID, the length must be 24 but it is %d, len(str))}_, err hex.Decode(id[:], []byte(str))if err ! nil {return err}}return err }func processUniqueBytes() [5]byte {var b [5]byte_, err : io.ReadFull(rand.Reader, b[:])if err ! nil {panic(fmt.Errorf(cannot initialize objectid package with crypto.rand.Reader: %w, err))}return b }func readRandomUint32() uint32 {var b [4]byte_, err : io.ReadFull(rand.Reader, b[:])if err ! nil {panic(fmt.Errorf(cannot initialize objectid package with crypto.rand.Reader: %w, err))}return (uint32(b[0]) 0) | (uint32(b[1]) 8) | (uint32(b[2]) 16) | (uint32(b[3]) 24) }func putUint24(b []byte, v uint32) {b[0] byte(v 16)b[1] byte(v 8)b[2] byte(v) }使用生成算法生成的ID 可以与环境无关、业务无关。通用性更好。
http://www.w-s-a.com/news/517819/

相关文章:

  • 重庆做网站公司贴吧廊坊公司快速建站
  • 海外贸易在什么网站做怎么排名到百度第一页
  • 线上注册公司是在哪个网站做高仿网站
  • 网站构架图网上推广平台哪个好
  • 公司网站首页图片素材vi设计的目的和意义
  • 网站的需求分析都有哪些内容济南营销型网站建设团队
  • 怎么选择优秀的网站建设公司生鲜网站开发
  • 如何编写网站建设销售的心得网站的权限管理怎么做
  • 网站业务员好做吗无忧网站优化
  • 网站随机代码网站建设费 账务处理
  • 商洛网站建设哪家好网站建设 织梦者
  • 怎么创建收费网站宁夏住房和城乡建设部网站
  • 怎么确认网站是什么语言做的用php和mysql做网站
  • 安徽做网站的公司有哪些星子网络公司
  • 肥西县重点工程建设管理局网站wordpress界面菜单怎么弄
  • 宁夏网站开发设计说明书wordpress主题背景图片
  • 同一个阿里云可以做两个网站吗织梦 帝国 学校网站
  • 城阳网站建设培训网站后台怎么上传文件
  • 重庆茂尔建设集团有限公司网站网页制作教程软件
  • 金湖建设工程质量监督网站高端网站建设公司哪里济南兴田德润实惠吗
  • 站酷设计网站官网入口文字设计seo网站推广工具
  • 专业移动网站建设网站建设软件dw
  • 摄影网站设计思想视觉传达毕业设计作品网站
  • 需要优化的网站有哪些设计装修app
  • 数据型网站建设东莞好的网站国外站建设价格
  • 网络营销方法有哪些举例seo应用领域有哪些
  • 建设银行官方网站官网做网站的专业叫什么
  • 矿区网站建设濮阳做网站的公司有哪些
  • 有什么网站可以自己做书甘肃建设厅网站首页
  • 门户网站建设哪专业怎么把自己做的网站登录到网上