Documentation
¶
Index ¶
- type GooseConfig
- type GooseFactory
- type GooseInstance
- func (g *GooseInstance) Close() error
- func (m *GooseInstance) Get() any
- func (g *GooseInstance) ID() string
- func (g *GooseInstance) Init(parent context.Context, env *pluginapi.HostEnv) error
- func (g *GooseInstance) Type() string
- func (g *GooseInstance) UpdateConfig(raw pluginapi.InstanceConfig) error
- type InstanceConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GooseConfig ¶
GooseConfig:单个 goose 实例的配置 GooseConfig holds configuration for a single goose instance.
type GooseFactory ¶
type GooseFactory struct{}
GooseFactory 同前,只是 New 不需要 env GooseFactory is unchanged: New does not receive env.
func (*GooseFactory) New ¶
func (f *GooseFactory) New(id string, raw pluginapi.InstanceConfig) (pluginapi.Instance, error)
func (*GooseFactory) Type ¶
func (f *GooseFactory) Type() string
type GooseInstance ¶
type GooseInstance struct {
// contains filtered or unexported fields
}
GooseInstance:具体实例实现 GooseInstance is a concrete plugin instance.
func (*GooseInstance) Close ¶
func (g *GooseInstance) Close() error
Close:cancel ctx + 等待所有协程退出 Close: cancel ctx + wait for all goroutines to exit.
func (*GooseInstance) Get ¶
func (m *GooseInstance) Get() any
func (*GooseInstance) ID ¶
func (g *GooseInstance) ID() string
func (*GooseInstance) Init ¶
Init:从 env 里拿到 logger + 用 parent ctx 派生实例 ctx Init: get logger from env + derive instance ctx from parent.
func (*GooseInstance) Type ¶
func (g *GooseInstance) Type() string
func (*GooseInstance) UpdateConfig ¶
func (g *GooseInstance) UpdateConfig(raw pluginapi.InstanceConfig) error
UpdateConfig:更新配置(这里简单更新 cfg,不重启协程;你也可以选择 Close+Init 重启) UpdateConfig: update config (simple cfg update; you may choose Close+Init to restart).
type InstanceConfig ¶
type InstanceConfig struct {
Model models.Goose
URL string `mapstructure:"url"`
// UnitID 是从站地址(0~247),为 0 时使用库默认值(一般是 1)
// UnitID is the slave/unit ID (0~247). 0 means "leave library default" (often 1).
UnitID uint8 `mapstructure:"unit_id"`
// Timeout 是单次请求超时(例如 "1s")
// Timeout is per-request timeout (e.g. "1s").
Timeout time.Duration `mapstructure:"timeout"`
// StartAddr 是起始寄存器地址
// StartAddr is the starting register address.
StartAddr uint16 `mapstructure:"start_addr"`
// Quantity 是读取的寄存器数量
// Quantity is the number of registers to read.
Quantity uint16 `mapstructure:"quantity"`
// RegType 寄存器类型:
// - "holding" => modbus.HOLDING_REGISTER
// - "input" => modbus.INPUT_REGISTER
//
// RegType indicates which register type to read:
// - "holding" => modbus.HOLDING_REGISTER
// - "input" => modbus.INPUT_REGISTER
RegType string `mapstructure:"reg_type"`
}
ModbusConfig:单个 modbus 实例的配置 ModbusConfig: configuration for a single modbus instance.