Files
tun/device/registry.go
Shiming Zhang 933f75497c Update
2022-02-26 20:22:53 +08:00

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)
}