func write(buf []byte, path string) error {
	file, err := os.OpenFile(path, os.O_WRONLY, 0600)
	if err != nil {
		return err
	}
	if _, err := file.Write(buf); err != nil {
		return err
	}
	return file.Close()
}
write opens a file for writing, writes the byte slice to it and closes the
file.
package gpio
import (
	"fmt"
	"io/ioutil"
	"os"
	"path/filepath"
	"strings"
	"syscall"
)
const (
	GPIO0     = 0
	GPIO1     = 1
	GPIO2     = 2
	GPIO3     = 3
	GPIO4     = 4
	GPIO7     = 7
	GPIO8     = 8
	GPIO9     = 9
	GPIO10    = 10
	GPIO11    = 11
	GPIO17    = 17
	GPIO18    = 18
	GPIO22    = 22
	GPIO23    = 23
	GPIO24    = 24
	GPIO25    = 25
	GPIOCount = 16  
)
const (
	gpiobase     = "/sys/class/gpio"
	exportPath   = "/sys/class/gpio/export"
	unexportPath = "/sys/class/gpio/unexport"
)
var (
	bytesSet   = []byte{'1'}
	bytesClear = []byte{'0'}
)
var watchEventCallbacks map[int]*pin
var epollFD int
func init() {
	setupEpoll()
	watchEventCallbacks = make(map[int]*pin)
}
func setupEpoll() {
	var err error
	epollFD, err = syscall.EpollCreate1(0)
	if err != nil {
		fmt.Println("Unable to create epoll FD: ", err.Error())
		os.Exit(1)
	}
	go func() {
		var epollEvents [GPIOCount]syscall.EpollEvent
		for {
			numEvents, err := syscall.EpollWait(epollFD, epollEvents[:], -1)
			if err != nil {
				if err == syscall.EAGAIN {
					continue
				}
				panic(fmt.Sprintf("EpollWait error: %v", err))
			}
			for i := 0; i < numEvents; i++ {
				if eventPin, exists := watchEventCallbacks[int(epollEvents[i].Fd)]; exists {
					if eventPin.initial {
						eventPin.initial = false
					} else {
						eventPin.callback()
					}
				}
			}
		}
	}()
}
type pin struct {
	number        int       
	numberAsBytes []byte    
	modePath      string    
	edgePath      string    
	valueFile     *os.File  
	callback      IRQEvent  
	initial       bool      
	err           error     
}
func OpenPin(n int, mode Mode) (Pin, error) {
	pinBase, err := expose(n)
	if err != nil {
		return nil, err
	}
	value, err := os.OpenFile(filepath.Join(pinBase, "value"), os.O_RDWR, 0600)
	if err != nil {
		return nil, err
	}
	p := &pin{
		number:    n,
		modePath:  filepath.Join(pinBase, "direction"),
		edgePath:  filepath.Join(pinBase, "edge"),
		valueFile: value,
		initial:   true,
	}
	if err := p.setMode(mode); err != nil {
		p.Close()
		return nil, err
	}
	return p, nil
}