client

package
v0.0.0-...-67f2643 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Overview

pkg/client/network_base.go

pkg/client/network_device.go

file: pkg/client/uci.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToContext

func AddToContext(ctx context.Context, u UbusRPC) context.Context

Types

type Call

type Call struct {
	SessionID session.SessionID
	Path      string
	Procedure string
	Signature Signature
}

Call 结构体现在是纯粹的、不可变的数据载体

type Change

type Change struct {
	Procedure string          `json:"procedure"`
	Section   string          `json:"section"`
	Type      uci.SectionType `json:"type,omitempty"`
	Option    string          `json:"option,omitempty"`
	Value     string          `json:"value,omitempty"`
}

type ClientOptions

type ClientOptions struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Timeout  uint   `json:"timeout"`
	URL      string `json:"url"`
}

type CtxKey

type CtxKey string

type ExitCode

type ExitCode int

implements ResultObject implements builtin.error always the first object of the Response tuple

func (ExitCode) Error

func (e ExitCode) Error() string

type LoginResult

type LoginResult struct {
	session.Session `json:",inline"`
}

result of a `session login` command

type LuciGetBoardJSONOptions

type LuciGetBoardJSONOptions struct{}

func (LuciGetBoardJSONOptions) GetResult

func (opts LuciGetBoardJSONOptions) GetResult(p Response) (u LuciGetBoardJSONResult, err error)

type LuciGetBoardJSONResult

type LuciGetBoardJSONResult struct {
	lucirpc.BoardInfo // ✅ 确保这里使用的是你新定义的 BoardInfo
}

type LuciGetDHCPLeasesOptions

type LuciGetDHCPLeasesOptions struct {
	Family int `json:"family"`
}

func (LuciGetDHCPLeasesOptions) GetResult

type LuciGetDHCPLeasesResult

type LuciGetDHCPLeasesResult struct {
	//                                      👇 这里是修改点
	Leases []lucirpc.DHCPLease `json:"dhcp_leases"`
}

type LuciGetDUIDHintsOptions

type LuciGetDUIDHintsOptions struct{}

func (LuciGetDUIDHintsOptions) GetResult

func (opts LuciGetDUIDHintsOptions) GetResult(p Response) (u LuciGetDUIDHintsResult, err error)

type LuciGetDUIDHintsResult

type LuciGetDUIDHintsResult struct {
	DUIDs map[string]string `json:"duids"`
}

type LuciGetHostHintsOptions

type LuciGetHostHintsOptions struct{}

func (LuciGetHostHintsOptions) GetResult

func (opts LuciGetHostHintsOptions) GetResult(p Response) (u LuciGetHostHintsResult, err error)

type LuciGetHostHintsResult

type LuciGetHostHintsResult struct {
	Hosts map[string]string `json:"hosts"`
}

type LuciGetNetworkDevicesOptions

type LuciGetNetworkDevicesOptions struct{}

func (LuciGetNetworkDevicesOptions) GetResult

type LuciGetNetworkDevicesResult

type LuciGetNetworkDevicesResult struct {
	Devices map[string]lucirpc.NetworkDevice `json:"devices"`
}

type LuciGetWirelessDevicesOptions

type LuciGetWirelessDevicesOptions struct{}

func (LuciGetWirelessDevicesOptions) GetResult

type LuciGetWirelessDevicesResult

type LuciGetWirelessDevicesResult struct {
	Devices map[string]lucirpc.WirelessDevice `json:"devices"`
}

type LuciRPCInterface

type LuciRPCInterface interface {
	GetNetworkDevices(ctx context.Context, opts LuciGetNetworkDevicesOptions) (r Response, err error)
	GetWirelessDevices(ctx context.Context, opts LuciGetWirelessDevicesOptions) (r Response, err error)
	GetHostHints(ctx context.Context, opts LuciGetHostHintsOptions) (r Response, err error)
	GetDUIDHints(ctx context.Context, opts LuciGetDUIDHintsOptions) (r Response, err error)
	GetBoardJSON(ctx context.Context, opts LuciGetBoardJSONOptions) (r Response, err error)
	GetDHCPLeases(ctx context.Context, opts LuciGetDHCPLeasesOptions) (r Response, err error)
}

type NetworkBaseInterface

type NetworkBaseInterface interface {
	Reload(ctx context.Context, opts NetworkReloadOptions) (Response, error)
}

type NetworkDeviceClient

type NetworkDeviceClient interface {
	Status(ctx context.Context, opts NetworkDeviceStatusOptions) (Response, error)
}

type NetworkDeviceStatusOptions

type NetworkDeviceStatusOptions struct {
	Name string `json:"name"`
}

Options

func (NetworkDeviceStatusOptions) GetResult

type NetworkDeviceStatusResult

type NetworkDeviceStatusResult struct {
	network.InterfaceInfo
}

Result

type NetworkDumpOptions

type NetworkDumpOptions struct{}

Options Structs

func (NetworkDumpOptions) GetResult

func (opts NetworkDumpOptions) GetResult(p Response) (u NetworkDumpResult, err error)

type NetworkDumpResult

type NetworkDumpResult struct {
	Interfaces []network.InterfaceInfo `json:"interface"`
}

Result Structs

type NetworkInterfaceClient

type NetworkInterfaceClient interface {
	// Dump 获取所有网络接口的信息
	Dump(ctx context.Context) (Response, error)
	// Status 获取指定网络接口的状态
	Status(ctx context.Context, interfaceName string) (Response, error)
	// Up 启动指定网络接口
	Up(ctx context.Context, interfaceName string) (Response, error)
	// Down 关闭指定网络接口
	Down(ctx context.Context, interfaceName string) (Response, error)
}

将 NetworkInterface 重命名为 NetworkInterfaceClient

type NetworkReloadOptions

type NetworkReloadOptions struct{}

Options

type NetworkStatusResult

type NetworkStatusResult struct {
	network.InterfaceInfo
}

NetworkStatusResult 保持不变,用于解析 Status 的返回结果

func GetStatusResult

func GetStatusResult(p Response) (u NetworkStatusResult, err error)

type Params

type Params []any

type Response

type Response []ResultObject

implements json.Marshaler and json.Unmarshaler effectively a tuple: Response[0] is always an int (ExitCode) Response[1] is always an xResult type (e.g. UCIResult)

func (Response) MarshalJSON

func (r Response) MarshalJSON() ([]byte, error)

custom MarshalJSON for Response

func (*Response) UnmarshalJSON

func (r *Response) UnmarshalJSON(data []byte) error

custom UnmarshalJSON for Response

type ResultObject

type ResultObject interface {
	// contains filtered or unexported methods
}

interface for content within a Response all ResultObjects must also have their own match function

type SessionInterface

type SessionInterface interface {
	Login(ctx context.Context, opts SessionLoginOptions) (r Response, err error)
}

type SessionLoginOptions

type SessionLoginOptions struct {
	Username string `json:"username"`
	Password string `json:"password"`
	Timeout  uint   `json:"timeout"`
}

implements Signature interface

func (SessionLoginOptions) GetResult

func (opts SessionLoginOptions) GetResult(p Response) (u LoginResult, err error)

type Signature

type Signature interface {
	// contains filtered or unexported methods
}

type UCIAddOptions

type UCIAddOptions struct {
	Config uci.ConfigName  `json:"config,omitempty"`
	Type   uci.SectionType `json:"type,omitempty"`
}

implements Signature interface

func (UCIAddOptions) GetResult

func (opts UCIAddOptions) GetResult(p Response) (u UCIAddResult, err error)

type UCIAddResult

type UCIAddResult struct {
	Section string `json:"section,omitempty"`
}

result of a `uci add` command

type UCIApplyOptions

type UCIApplyOptions struct {
	Rollback uci.StringBool `json:"rollback,omitempty"`
	Timeout  int            `json:"timeout,omitempty"`
}

does not have a GetResult func because this command only returns the exit code implements Signature interface

type UCIChangesOptions

type UCIChangesOptions struct {
	Config uci.ConfigName `json:"config,omitempty"`
}

implements Signature interface

func (UCIChangesOptions) GetResult

func (opts UCIChangesOptions) GetResult(p Response) (u UCIChangesResult, err error)

type UCIChangesResult

type UCIChangesResult struct {
	Changes map[uci.ConfigName][]Change `json:"changes"`
}

type UCIConfigsOptions

type UCIConfigsOptions struct{}

implements Signature interface empty struct because there are no options but it has a special return type so we're following the same pattern as the other commands to get the result

func (UCIConfigsOptions) GetResult

func (opts UCIConfigsOptions) GetResult(p Response) (u UCIConfigsResult, err error)

type UCIConfigsResult

type UCIConfigsResult struct {
	Configs []uci.ConfigName `json:"configs,omitempty"`
}

result of a `uci configs` command

type UCIDeleteOptions

type UCIDeleteOptions struct {
	Config  uci.ConfigName `json:"config,omitempty"`
	Section string         `json:"section,omitempty"`
	Type    string         `json:"type,omitempty"`
	Option  string         `json:"option,omitempty"`
}

does not have a GetResult func because this command only returns the exit code implements Signature interface

type UCIGetOptions

type UCIGetOptions struct {
	Config  uci.ConfigName `json:"config,omitempty"`
	Section string         `json:"section,omitempty"`
	Type    string         `json:"type,omitempty"`
	Option  string         `json:"option,omitempty"`
}

implements Signature interface

func (UCIGetOptions) GetResult

func (opts UCIGetOptions) GetResult(p Response) (u UCIGetResult, err error)

type UCIGetResult

type UCIGetResult struct {
	// if any combination of Config, Section, and Type are specified, return a set of
	// UCIConfigSection(s)
	SectionArray []uci.UCIConfigSection `json:"sectionArray,omitempty"`
	// if Option is set in UCIGetOptions, return a single option's value
	Option map[string]uci.DynamicList `json:"option,omitempty"`
}

result of a `uci get` command

type UCIInterface

type UCIInterface interface {
	Add(ctx context.Context, opts UCIAddOptions) (r Response, err error)
	Apply(ctx context.Context, opts UCIApplyOptions) (r Response, err error)
	Changes(ctx context.Context, opts UCIChangesOptions) (r Response, err error)
	Configs(ctx context.Context, opts UCIConfigsOptions) (r Response, err error)
	Delete(ctx context.Context, opts UCIDeleteOptions) (r Response, err error)
	Get(ctx context.Context, opts UCIGetOptions) (r Response, err error)
	Revert(ctx context.Context, opts UCIRevertOptions) (r Response, err error)
	Set(ctx context.Context, opts UCISetOptions) (r Response, err error)
}

type UCIRevertOptions

type UCIRevertOptions struct {
	Config uci.ConfigName `json:"config,omitempty"`
}

does not have a GetResult func because this command only returns the exit code implements Signature interface

type UCISetOptions

type UCISetOptions struct {
	Config  uci.ConfigName              `json:"config,omitempty"`
	Section string                      `json:"section,omitempty"`
	Values  uci.UCIConfigSectionOptions `json:"values,omitempty"`
}

does not have a GetResult func because this command only returns the exit code implements Signature interface

type UbusRPC

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

the primary client and caller object

func GetFromContext

func GetFromContext(ctx context.Context) *UbusRPC

func NewUbusRPC

func NewUbusRPC(ctx context.Context, opts *ClientOptions) (*UbusRPC, error)

pkg/client/client.go (最终版本)

func (*UbusRPC) Load

func (u *UbusRPC) Load() (string, error)

func (*UbusRPC) LuciRPC

func (u *UbusRPC) LuciRPC() LuciRPCInterface

Added LuciRPC method

func (*UbusRPC) Network

func (u *UbusRPC) Network() NetworkBaseInterface

Network() 返回一个可以调用 Reload/Restart 等方法的 network 客户端

func (*UbusRPC) NetworkDevice

func (u *UbusRPC) NetworkDevice() NetworkDeviceClient

NetworkDevice() 返回一个可以调用 Status 等方法的 device 客户端

func (*UbusRPC) NetworkInterface

func (u *UbusRPC) NetworkInterface() NetworkInterfaceClient

NetworkInterface() 返回一个可以调用 Dump/Status/Up/Down 等方法的 interface 客户端

func (*UbusRPC) Save

func (u *UbusRPC) Save()

func (*UbusRPC) Session

func (u *UbusRPC) Session() SessionInterface

func (*UbusRPC) UCI

func (u *UbusRPC) UCI() UCIInterface

Source Files

  • client.go
  • lucirpc.go
  • network_base.go
  • network_device.go
  • network_interface.go
  • response.go
  • session.go
  • ubus.go
  • uci.go

Jump to

Keyboard shortcuts

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