discovery

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandHandler

type CommandHandler func(from net.Addr, env MessageEnvelope)

CommandHandler 定义了处理接收到命令的函数签名

type Device

type Device struct {
	UUID     string
	Name     string
	IP       string
	Port     int
	Version  string
	LastSeen time.Time
}

Device 结构体表示发现到的设备信息

type Discovery

type Discovery struct {
	// contains filtered or unexported fields
}

Discovery 结构体封装了设备发现和通信的逻辑

func NewDiscovery

func NewDiscovery(name, ver string, logger Logger) *Discovery

NewDiscovery 创建一个新的 Discovery 实例

func (*Discovery) GetDevices

func (d *Discovery) GetDevices() []*Device

GetDevices 返回当前发现到的设备列表

func (*Discovery) RegisterHandler

func (d *Discovery) RegisterHandler(cmd string, handler CommandHandler)

RegisterHandler 注册命令处理器

func (*Discovery) RequestResponse

func (d *Discovery) RequestResponse(env MessageEnvelope, timeout time.Duration) (MessageEnvelope, error)

RequestResponse 发送请求并等待响应

func (*Discovery) Send

func (d *Discovery) Send(env MessageEnvelope) error

Send 发送消息

func (*Discovery) Start

func (d *Discovery) Start() error

Start 启动设备发现服务

func (*Discovery) Stop

func (d *Discovery) Stop()

Stop 停止设备发现服务

type Logger

type Logger interface {
	Info(msg string, args ...any)
	Error(msg string, args ...any)
}

Logger 接口定义了日志方法

type MessageEnvelope

type MessageEnvelope struct {
	FromUUID string          `json:"fromUuid"`
	SendType string          `json:"sendType"`          // "announce" | "spec" | "response"
	SendTo   string          `json:"sendTo,omitempty"`  // 单播目标
	Command  string          `json:"command"`           // 命令
	TaskID   string          `json:"taskId"`            // 任务 ID
	Payload  json.RawMessage `json:"payload,omitempty"` // 附带参数
}

MessageEnvelope 定义了在网络中传输的消息结构

type StdLogger

type StdLogger struct{}

StdLogger 是 Logger 接口的标准实现

func (*StdLogger) Error

func (l *StdLogger) Error(msg string, args ...any)

func (*StdLogger) Info

func (l *StdLogger) Info(msg string, args ...any)

Jump to

Keyboard shortcuts

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