Documentation
¶
Overview ¶
pkg/client/network_base.go
pkg/client/network_device.go
file: pkg/client/uci.go
Index ¶
- func AddToContext(ctx context.Context, u UbusRPC) context.Context
- type Call
- type Change
- type ClientOptions
- type CtxKey
- type ExitCode
- type LoginResult
- type LuciGetBoardJSONOptions
- type LuciGetBoardJSONResult
- type LuciGetDHCPLeasesOptions
- type LuciGetDHCPLeasesResult
- type LuciGetDUIDHintsOptions
- type LuciGetDUIDHintsResult
- type LuciGetHostHintsOptions
- type LuciGetHostHintsResult
- type LuciGetNetworkDevicesOptions
- type LuciGetNetworkDevicesResult
- type LuciGetWirelessDevicesOptions
- type LuciGetWirelessDevicesResult
- type LuciRPCInterface
- type NetworkBaseInterface
- type NetworkDeviceClient
- type NetworkDeviceStatusOptions
- type NetworkDeviceStatusResult
- type NetworkDumpOptions
- type NetworkDumpResult
- type NetworkInterfaceClient
- type NetworkReloadOptions
- type NetworkStatusResult
- type Params
- type Response
- type ResultObject
- type SessionInterface
- type SessionLoginOptions
- type Signature
- type UCIAddOptions
- type UCIAddResult
- type UCIApplyOptions
- type UCIChangesOptions
- type UCIChangesResult
- type UCIConfigsOptions
- type UCIConfigsResult
- type UCIDeleteOptions
- type UCIGetOptions
- type UCIGetResult
- type UCIInterface
- type UCIRevertOptions
- type UCISetOptions
- type UbusRPC
- func (u *UbusRPC) Load() (string, error)
- func (u *UbusRPC) LuciRPC() LuciRPCInterface
- func (u *UbusRPC) Network() NetworkBaseInterface
- func (u *UbusRPC) NetworkDevice() NetworkDeviceClient
- func (u *UbusRPC) NetworkInterface() NetworkInterfaceClient
- func (u *UbusRPC) Save()
- func (u *UbusRPC) Session() SessionInterface
- func (u *UbusRPC) UCI() UCIInterface
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Call ¶
Call 结构体现在是纯粹的、不可变的数据载体
type Change ¶
type ClientOptions ¶
type ExitCode ¶
type ExitCode int
implements ResultObject implements builtin.error always the first object of the Response tuple
type LoginResult ¶
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 LuciGetDHCPLeasesOptions ¶
type LuciGetDHCPLeasesOptions struct {
Family int `json:"family"`
}
func (LuciGetDHCPLeasesOptions) GetResult ¶
func (opts LuciGetDHCPLeasesOptions) GetResult(p Response) (u LuciGetDHCPLeasesResult, err error)
type LuciGetDHCPLeasesResult ¶
type LuciGetDUIDHintsOptions ¶
type LuciGetDUIDHintsOptions struct{}
func (LuciGetDUIDHintsOptions) GetResult ¶
func (opts LuciGetDUIDHintsOptions) GetResult(p Response) (u LuciGetDUIDHintsResult, err error)
type LuciGetDUIDHintsResult ¶
type LuciGetHostHintsOptions ¶
type LuciGetHostHintsOptions struct{}
func (LuciGetHostHintsOptions) GetResult ¶
func (opts LuciGetHostHintsOptions) GetResult(p Response) (u LuciGetHostHintsResult, err error)
type LuciGetHostHintsResult ¶
type LuciGetNetworkDevicesOptions ¶
type LuciGetNetworkDevicesOptions struct{}
func (LuciGetNetworkDevicesOptions) GetResult ¶
func (opts LuciGetNetworkDevicesOptions) GetResult(p Response) (u LuciGetNetworkDevicesResult, err error)
type LuciGetNetworkDevicesResult ¶
type LuciGetNetworkDevicesResult struct {
Devices map[string]lucirpc.NetworkDevice `json:"devices"`
}
type LuciGetWirelessDevicesOptions ¶
type LuciGetWirelessDevicesOptions struct{}
func (LuciGetWirelessDevicesOptions) GetResult ¶
func (opts LuciGetWirelessDevicesOptions) GetResult(p Response) (u LuciGetWirelessDevicesResult, err error)
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 ¶
func (opts NetworkDeviceStatusOptions) GetResult(p Response) (u NetworkDeviceStatusResult, err error)
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 NetworkStatusResult ¶
type NetworkStatusResult struct {
network.InterfaceInfo
}
NetworkStatusResult 保持不变,用于解析 Status 的返回结果
func GetStatusResult ¶
func GetStatusResult(p Response) (u NetworkStatusResult, err error)
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 ¶
custom MarshalJSON 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 NewUbusRPC ¶
func NewUbusRPC(ctx context.Context, opts *ClientOptions) (*UbusRPC, error)
pkg/client/client.go (最终版本)
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) 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