From b9ede88d27ab121a6883efa2ac8981a67ec826ce Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Thu, 10 Dec 2020 23:08:49 +0900 Subject: [PATCH] added more strict type hinting --- bootloader.go | 8 ++++++++ console.go | 10 ++++++++++ memory_balloon.go | 8 ++++++++ network.go | 12 ++++++++++++ socket.go | 8 ++++++++ storage.go | 16 ++++++++++++++++ 6 files changed, 62 insertions(+) diff --git a/bootloader.go b/bootloader.go index ebfaf76..96f7b89 100644 --- a/bootloader.go +++ b/bootloader.go @@ -15,8 +15,14 @@ import ( // see: LinuxBootLoader type BootLoader interface { NSObject + + bootLoader() } +type baseBootLoader struct{} + +func (*baseBootLoader) bootLoader() {} + var _ BootLoader = (*LinuxBootLoader)(nil) // LinuxBootLoader Boot loader configuration for a Linux kernel. @@ -25,6 +31,8 @@ type LinuxBootLoader struct { initrdPath string cmdLine string pointer + + *baseBootLoader } func (b *LinuxBootLoader) String() string { diff --git a/console.go b/console.go index 074e10c..b6146ff 100644 --- a/console.go +++ b/console.go @@ -16,8 +16,14 @@ import ( // A serial port attachment defines how the virtual machine's serial port interfaces with the host system. type SerialPortAttachment interface { NSObject + + serialPortAttachment() } +type baseSerialPortAttachment struct{} + +func (*baseSerialPortAttachment) serialPortAttachment() {} + var _ SerialPortAttachment = (*FileHandleSerialPortAttachment)(nil) // FileHandleSerialPortAttachment defines a serial port attachment from a file handle. @@ -26,6 +32,8 @@ var _ SerialPortAttachment = (*FileHandleSerialPortAttachment)(nil) // see: https://developer.apple.com/documentation/virtualization/vzfilehandleserialportattachment?language=objc type FileHandleSerialPortAttachment struct { pointer + + *baseSerialPortAttachment } // NewFileHandleSerialPortAttachment intialize the FileHandleSerialPortAttachment from file handles. @@ -56,6 +64,8 @@ var _ SerialPortAttachment = (*FileSerialPortAttachment)(nil) // see: https://developer.apple.com/documentation/virtualization/vzfileserialportattachment?language=objc type FileSerialPortAttachment struct { pointer + + *baseSerialPortAttachment } // NewFileSerialPortAttachment initialize the FileSerialPortAttachment from a path of a file. diff --git a/memory_balloon.go b/memory_balloon.go index 330c492..5315ba6 100644 --- a/memory_balloon.go +++ b/memory_balloon.go @@ -11,8 +11,14 @@ import "runtime" // MemoryBalloonDeviceConfiguration for a memory balloon device configuration. type MemoryBalloonDeviceConfiguration interface { NSObject + + memoryBalloonDeviceConfiguration() } +type baseMemoryBalloonDeviceConfiguration struct{} + +func (*baseMemoryBalloonDeviceConfiguration) memoryBalloonDeviceConfiguration() {} + var _ MemoryBalloonDeviceConfiguration = (*VirtioTraditionalMemoryBalloonDeviceConfiguration)(nil) // VirtioTraditionalMemoryBalloonDeviceConfiguration is a configuration of the Virtio traditional memory balloon device. @@ -20,6 +26,8 @@ var _ MemoryBalloonDeviceConfiguration = (*VirtioTraditionalMemoryBalloonDeviceC // see: https://developer.apple.com/documentation/virtualization/vzvirtiotraditionalmemoryballoondeviceconfiguration?language=objc type VirtioTraditionalMemoryBalloonDeviceConfiguration struct { pointer + + *baseMemoryBalloonDeviceConfiguration } // NewVirtioTraditionalMemoryBalloonDeviceConfiguration creates a new VirtioTraditionalMemoryBalloonDeviceConfiguration. diff --git a/network.go b/network.go index c125ce3..105148b 100644 --- a/network.go +++ b/network.go @@ -40,6 +40,8 @@ type BridgedNetwork interface { // see: https://developer.apple.com/documentation/virtualization/vznatnetworkdeviceattachment?language=objc type NATNetworkDeviceAttachment struct { pointer + + *baseNetworkDeviceAttachment } var _ NetworkDeviceAttachment = (*NATNetworkDeviceAttachment)(nil) @@ -69,6 +71,8 @@ func NewNATNetworkDeviceAttachment() *NATNetworkDeviceAttachment { // see: https://developer.apple.com/documentation/virtualization/vzbridgednetworkdeviceattachment?language=objc type BridgedNetworkDeviceAttachment struct { pointer + + *baseNetworkDeviceAttachment } var _ NetworkDeviceAttachment = (*BridgedNetworkDeviceAttachment)(nil) @@ -95,6 +99,8 @@ func NewBridgedNetworkDeviceAttachment(networkInterface BridgedNetwork) *Bridged // see: https://developer.apple.com/documentation/virtualization/vzfilehandlenetworkdeviceattachment?language=objc type FileHandleNetworkDeviceAttachment struct { pointer + + *baseNetworkDeviceAttachment } var _ NetworkDeviceAttachment = (*FileHandleNetworkDeviceAttachment)(nil) @@ -120,8 +126,14 @@ func NewFileHandleNetworkDeviceAttachment(file *os.File) *FileHandleNetworkDevic // see: https://developer.apple.com/documentation/virtualization/vznetworkdeviceattachment?language=objc type NetworkDeviceAttachment interface { NSObject + + networkDeviceAttachment() } +type baseNetworkDeviceAttachment struct{} + +func (*baseNetworkDeviceAttachment) networkDeviceAttachment() {} + // VirtioNetworkDeviceConfiguration is configuration of a paravirtualized network device of type Virtio Network Device. // // The communication channel used on the host is defined through the attachment. diff --git a/socket.go b/socket.go index 17f4997..cc62d6f 100644 --- a/socket.go +++ b/socket.go @@ -11,8 +11,14 @@ import "runtime" // SocketDeviceConfiguration for a socket device configuration. type SocketDeviceConfiguration interface { NSObject + + socketDeviceConfiguration() } +type baseSocketDeviceConfiguration struct{} + +func (*baseSocketDeviceConfiguration) socketDeviceConfiguration() {} + var _ SocketDeviceConfiguration = (*VirtioSocketDeviceConfiguration)(nil) // VirtioSocketDeviceConfiguration is a configuration of the Virtio socket device. @@ -22,6 +28,8 @@ var _ SocketDeviceConfiguration = (*VirtioSocketDeviceConfiguration)(nil) // see: https://developer.apple.com/documentation/virtualization/vzvirtiosocketdeviceconfiguration?language=objc type VirtioSocketDeviceConfiguration struct { pointer + + *baseSocketDeviceConfiguration } // NewVirtioSocketDeviceConfiguration creates a new VirtioSocketDeviceConfiguration. diff --git a/storage.go b/storage.go index 29fb340..d29493c 100644 --- a/storage.go +++ b/storage.go @@ -8,12 +8,18 @@ package vz import "C" import "runtime" +type baseStorageDeviceAttachment struct{} + +func (*baseStorageDeviceAttachment) storageDeviceAttachment() {} + // StorageDeviceAttachment for a storage device attachment. // // A storage device attachment defines how a virtual machine storage device interfaces with the host system. // see: https://developer.apple.com/documentation/virtualization/vzstoragedeviceattachment?language=objc type StorageDeviceAttachment interface { NSObject + + storageDeviceAttachment() } var _ StorageDeviceAttachment = (*DiskImageStorageDeviceAttachment)(nil) @@ -25,6 +31,8 @@ var _ StorageDeviceAttachment = (*DiskImageStorageDeviceAttachment)(nil) // see: https://developer.apple.com/documentation/virtualization/vzdiskimagestoragedeviceattachment?language=objc type DiskImageStorageDeviceAttachment struct { pointer + + *baseStorageDeviceAttachment } // NewDiskImageStorageDeviceAttachment initialize the attachment from a local file path. @@ -59,8 +67,14 @@ func NewDiskImageStorageDeviceAttachment(diskPath string, readOnly bool) (*DiskI // StorageDeviceConfiguration for a storage device configuration. type StorageDeviceConfiguration interface { NSObject + + storageDeviceConfiguration() } +type baseStorageDeviceConfiguration struct{} + +func (*baseStorageDeviceConfiguration) storageDeviceConfiguration() {} + var _ StorageDeviceConfiguration = (*VirtioBlockDeviceConfiguration)(nil) // VirtioBlockDeviceConfiguration is a configuration of a paravirtualized storage device of type Virtio Block Device. @@ -73,6 +87,8 @@ var _ StorageDeviceConfiguration = (*VirtioBlockDeviceConfiguration)(nil) // see: https://developer.apple.com/documentation/virtualization/vzvirtioblockdeviceconfiguration?language=objc type VirtioBlockDeviceConfiguration struct { pointer + + *baseStorageDeviceConfiguration } // NewVirtioBlockDeviceConfiguration initialize a VZVirtioBlockDeviceConfiguration with a device attachment.