interfaceGUID

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2020 License: Apache-2.0 Imports: 5 Imported by: 2

README

interfaceGUID

interfaceGUID exposes a single function CalculateGUID which calculates a unique deterministic value based on the type provided. It is to be used when communicating with remote services to quickly assert common knowledge before starting to communicate, for example via encoding/gob.

GoDoc Build Status Coverage Status

Example

type MyService interface {
  ...
}

guid := interfaceGUID.CalculateGUID(reflect.TypeOf((*MyService)(nil)).Elem())
// Then compare the string with the remote service.

Documentation

Overview

Package interfaceGUID exposes one function to calculate a unique identifier for an interface.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Calculate

func Calculate(t reflect.Type) string

Calculate returns the hex encoded string of the SHA-256 hash of a reflected type, normally an interface.

The reflected type is traversed recursively up to all native types referenced. The value is dependent on the referenced type names, methods and their order. The name of the type itself is not taken in account.

The purpose of this function is to get into a quick common agreement between two remote parties, so that follow up communication can be done with gob or another communication mechanism.

See test cases for more details.

Example
type Foo interface {
	Baz1(int) error
	Baz2()
}
fmt.Printf("%s\n", Calculate(reflect.TypeOf((*Foo)(nil)).Elem()))
Output:

ee2fbefc01ff399e106213e5eab0f3a36c245f195195bd36a2058c115637e05d

Types

This section is empty.

Jump to

Keyboard shortcuts

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