hardware

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 7 Imported by: 0

README

hardware(硬件信息)

计算设备序列号

package sample
import "github.com/lishimeng/x/hardware"
import "testing"

// WithSnFile: 设置序列号文件
// WithNameFile: 设置设备名文件

func TestGenId(t *testing.T) {
	var err error
	err = hardware.Setup(
		hardware.WithNameFile("./name.test.txt"), 
		hardware.WithSnFile("./sn.test.txt"))
	if err != nil {
		t.Fatalf("Setup err: %v", err)
		return
	}
	err = hardware.UpdateName("thisisname")
	if err != nil {
		t.Fatalf("Update err: %v", err)
		return
	}
	t.Logf("sn:%s", hardware.GetSN())
	t.Logf("device_name:%s", hardware.GetName())
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var WithNameFile = func(name string) OptFunc {
	return func(opt *Opt) {
		opt.DeviceNamePath = name
	}
}

WithNameFile 自定义设备名文件

View Source
var WithSnFile = func(name string) OptFunc {
	return func(opt *Opt) {
		opt.SerialNoPath = name
	}
}

WithSnFile 自定义序列号文件

Functions

func GetName

func GetName() string

func GetSN

func GetSN() string

func Setup

func Setup(opts ...OptFunc) (err error)

func UpdateName

func UpdateName(name string) (err error)

Types

type Opt

type Opt struct {
	DeviceNamePath string // 设备名文件, 可加载
	SerialNoPath   string // 序列号文件, 单向写入不可加载
	// contains filtered or unexported fields
}

func (*Opt) Load

func (opt *Opt) Load()

func (*Opt) Save

func (opt *Opt) Save() (err error)

Save 保存数据

type OptFunc

type OptFunc func(opt *Opt)

Jump to

Keyboard shortcuts

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