Help us shape the future of Go! Take the 2026 Go Developer Survey

deviceid

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2025 License: MIT Imports: 9 Imported by: 0

README

deviceid

A small library to generate a 'device ID' to uniquely identify a computer.

Heavily inspired by the C# library written by Matthew King - DeviceId

Motivation

I couldn't find a device id library for golang that created a unique ID with the level of control and options I was looking for.

I'd used DeviceId by Matthew King in some C# projects, so I'd been spoiled in that language, and wanted something similar for an internal work project. So I created this.

Installation

Just use go get.

go get github.com/craig-jarvis/deviceid

Usage

Create a builder, add at least one component, then generate an id

var err error
bldr := deviceid.NewBuilder()
err = bldr.AddSerialNumber()
if err != nil {
	// handle err
}

d, err = bldr.GetDeviceId()
if err != nil {
	// handle err
}

alternatively, you can use the opinionated GetDeviceIdWithDefaults method.

This method includes the AddSerialNumber, and AddSystemUuid elements. On windows, it also includes AddWindowsDeviceId and AddWindowsMachineGuid

bldr := deviceid.NewBuilder()
d, err = bldr.GetDeviceIdWithDefaults()
if err != nil {
	// handle err
}
What can you include in a device identifier
  • AddMachineName adds the host name to the device identifier.
  • AddMacAddress adds all the MAC addresses to the device identifier. Method supports excluding the default docker bridge interface named "docker0".
  • AddOsVersion adds the current OS version to the device identifier.
  • AddSerialNumber adds the motherboard serial number to the device identifier.
  • AddSystemUuid adds the system UUID to the device identifier.
  • AddWindowsDeviceId adds the Windows Device ID (also known as Machine ID or Advertising ID) to the device identifier. This value is the one displayed as "Device ID" in the Windows Device Specifications UI.
  • AddWindowsMachineGuid adds the machine GUID from HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography to the device identifier.

Copyright (c) 2025 Craig Jarvis Distributed under the MIT License. Refer to LICENSE for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct {
	Debug bool
	Trace bool
	// contains filtered or unexported fields
}

func NewBuilder

func NewBuilder() *Builder

func (*Builder) AddMacAddress

func (b *Builder) AddMacAddress(excludeDockerBridge bool) error

func (*Builder) AddMachineName

func (b *Builder) AddMachineName() error

func (*Builder) AddOsVersion

func (b *Builder) AddOsVersion() error

func (*Builder) AddSerialNumber

func (b *Builder) AddSerialNumber() error

func (*Builder) AddSystemUuid

func (b *Builder) AddSystemUuid() error

func (*Builder) AddWindowsDeviceId

func (b *Builder) AddWindowsDeviceId() error

func (*Builder) AddWindowsMachineGuid

func (b *Builder) AddWindowsMachineGuid() error

func (*Builder) GetDeviceId

func (b *Builder) GetDeviceId() (string, error)

func (*Builder) GetDeviceIdWithDefaults

func (b *Builder) GetDeviceIdWithDefaults() (string, error)

Jump to

Keyboard shortcuts

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