hashstructure

Get hash values for arbitrary values in Go (golang).

  • 所有者: mitchellh/hashstructure
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

hashstructure GoDoc

hashstructure is a Go library for creating a unique hash value
for arbitrary values in Go.

This can be used to key values in a hash (for use in a map, set, etc.)
that are complex. The most common use case is comparing two values without
sending data across the network, caching values locally (de-dup), and so on.

Features

  • Hash any arbitrary Go value, including complex types.

  • Tag a struct field to ignore it and not affect the hash value.

  • Tag a slice type struct field to treat it as a set where ordering
    doesn't affect the hash code but the field itself is still taken into
    account to create the hash value.

  • Optionally specify a custom hash function to optimize for speed, collision
    avoidance for your data set, etc.

  • Optionally hash the output of .String() on structs that implement fmt.Stringer,
    allowing effective hashing of time.Time

Installation

Standard go get:

$ go get github.com/mitchellh/hashstructure

Usage & Example

For usage and examples see the Godoc.

A quick code example is shown below:

type ComplexStruct struct {
    Name     string
    Age      uint
    Metadata map[string]interface{}
}

v := ComplexStruct{
    Name: "mitchellh",
    Age:  64,
    Metadata: map[string]interface{}{
        "car":      true,
        "location": "California",
        "siblings": []string{"Bob", "John"},
    },
}

hash, err := hashstructure.Hash(v, nil)
if err != nil {
    panic(err)
}

fmt.Printf("%d", hash)
// Output:
// 2307517237273902113

主要指標

概覽
名稱與所有者mitchellh/hashstructure
主編程語言Go
編程語言Go (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2016-01-07 18:30:08
推送於2023-01-03 15:13:06
最后一次提交2021-05-27 16:24:52
發布數5
最新版本名稱v2.0.2 (發布於 )
第一版名稱v1.0.0 (發布於 )
用户参与
星數759
關注者數9
派生數90
提交數73
已啟用問題?
問題數21
打開的問題數8
拉請求數14
打開的拉請求數6
關閉的拉請求數6
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?