Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openPin() architect improvement #12

Open
ixvick opened this issue Oct 24, 2018 · 1 comment
Open

openPin() architect improvement #12

ixvick opened this issue Oct 24, 2018 · 1 comment

Comments

@ixvick
Copy link

ixvick commented Oct 24, 2018

in
func openPin(p Pin, write bool) Pin {
}

It would be better not to call fmt.Printf() and os.Exit(1) inside openPin()
instead please return p, err

@ixvick
Copy link
Author

ixvick commented Oct 24, 2018

func openPin(p Pin, write bool) (Pin, error) {
	flags := os.O_RDONLY
	if write {
		flags = os.O_RDWR
	}
	f, err := os.OpenFile(fmt.Sprintf("/sys/class/gpio/gpio%d/value", p.Number), flags, 0600)
	if err != nil {
                return p, err
	}
	p.f = f
	return p, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant