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

Code examples #85

Closed
wants to merge 2 commits into from
Closed

Code examples #85

wants to merge 2 commits into from

Conversation

muhlemmer
Copy link
Contributor

@muhlemmer muhlemmer commented Mar 19, 2020

Both the client.ConfigureDevice() and client.Device() expect a non-existing wg-foobar interface, so no special tests are required like for integration tests.

Closes #37

@muhlemmer
Copy link
Contributor Author

muhlemmer commented Mar 19, 2020

Fails on staticcheck, on lines not affected by this PR. Note, running staticcheck against master produces the same errors.

Copy link
Member

@mdlayher mdlayher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

I don't think the key generation examples are really necessary; they essentially amount to an input, an error check, and printing something.

I think it's fine to to have an example for Device/Devices/ConfigureDevice, but there should be no global state involved, and all errors should be checked. I'm not worried about devices named wg-foobar existing on real machines. And I think these sorts of examples should not have any output as we would not want to manipulate the system's state by default. As long as they pass compilation, the user can take them and run them locally.

- Single example for priv / pub key generation
- Avoid globale state for client examples
- Single example for complete client operation
- Drop print output requirements
@muhlemmer
Copy link
Contributor Author

I was in the misunderstanding that Go examples are always ran. I've removed the output requirement and the examples no longer run. wg0 is now used.

Before, I used the global state to split the examples for New() and Client methods. Basically to make the compile work. In the latest commit I've merged the New() and client.ConfigureDevice() into one example Also doing proper error checks now. The client.Device() example is also dropped, as the logic is the check os.IsNotExist(err), which is already shown in client.ConfigureDevice(). This way i could drop the global state for client.

The wgtypes example is now condensed to a single example to show generation of a Private key and Public key from it.

Hope this is better :)

@muhlemmer muhlemmer requested a review from mdlayher March 27, 2020 16:47
@th3wingman
Copy link

Being new to the library I do appreciate the example, thank you! Helped me get going after being stuck for quite some time.

@muhlemmer muhlemmer closed this Apr 22, 2023
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

Successfully merging this pull request may close these issues.

wgctrl: expand documentation and add examples
3 participants