You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
340 B

package main
import (
"fmt"
"os"
)
var devices = map[string]*os.File{}
func GetDevice(name string) (*os.File, error) {
if dev, ok := devices[name]; ok {
return dev, nil
}
dev, err := os.OpenFile("/dev/"+name, os.O_RDWR, 0644)
if err != nil {
return nil, fmt.Errorf("open: %w", err)
}
devices[name] = dev
return dev, nil
}