mirror of
https://github.com/wzshiming/tun.git
synced 2025-12-24 13:18:15 +08:00
19 lines
403 B
Go
19 lines
403 B
Go
package device
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
var registry = map[string]func(name string, mtu uint32) (Device, error){}
|
|
|
|
func Registry(name string, fun func(name string, mtu uint32) (Device, error)) {
|
|
registry[name] = fun
|
|
}
|
|
|
|
func NewDevice(device, name string, mtu uint32) (Device, error) {
|
|
if fun, ok := registry[device]; ok {
|
|
return fun(name, mtu)
|
|
}
|
|
return nil, fmt.Errorf("device %s not found", device)
|
|
}
|