hasher

package module
v0.0.0-...-4ec56e2 Latest Latest
Warning

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

Go to latest
Published: May 4, 2020 License: MIT Imports: 5 Imported by: 1

README

Build Status Documentation

Hasher | Geoff Ford

The hasher package provides the Hash() function that returns a DataHash.

An example of use is available in GoDocs.

The objective here is to ensure consistency of hashing, regardless of the interface{} object that is passed to the Hash() function. If the argument is not of type []byte then gob is used to convert the argument to a []byte slice.

The hashing algorithm used is sha256.Sum256.

Installing and building the library

This project requires Go 1.14.2

To use this package in your own code, install it using go get:

go get github.com/gford1000-go/hasher

Then, you can include it in your project:

import "github.com/gford1000-go/hasher"

Alternatively, you can clone it yourself:

git clone https://github.com/gford1000-go/hasher.git

Testing and benchmarking

To run all tests, cd into the directory and use:

go test -v

Documentation

Overview

Example
type Inner struct {
	B []int
}
type Outer struct {
	A int
	B *Inner
	C string
}

v := &Outer{
	A: 42,
	B: &Inner{B: []int{101, 102, 103}},
	C: "Hello",
}

h, _ := Hash(v) // Illustrates hashing arbitrary objects
fmt.Println(h)
Output:

[74 175 82 242 158 82 154 251 165 204 11 169 52 189 125 83 245 147 182 197 53 143 167 187 38 128 108 203 210 240 5 226]

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataHash

type DataHash [32]byte

DataHash is the type of a hash value

var InvalidHash DataHash

InvalidHash is an invalid hash value - not initialised

func Hash

func Hash(i interface{}) (DataHash, error)

Hash returns a DataHash of the supplied interface{}. If the interface{} is a struct, then only public attributes will be used to construct the DataHash

Jump to

Keyboard shortcuts

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