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

Backport client code generation from https://github.com/ubiquiti-community/go-unifi #236

Open
filipowm opened this issue Jan 3, 2025 · 3 comments

Comments

@filipowm
Copy link
Contributor

filipowm commented Jan 3, 2025

Idea is to backport client code generation from https://github.com/ubiquiti-community/go-unifi. It is based on following client template https://github.com/ubiquiti-community/go-unifi/blob/main/fields/client.go.tmpl , which generates code like on following example of channel_plan.go:

// Code generated from ace.jar fields *.json files
// DO NOT EDIT.

package unifi

import (
	"context"
)

func (c *Client) ListChannelPlan(ctx context.Context, site string) ([]ChannelPlan, error) {
	return c.listChannelPlan(ctx, site)
}

func (c *Client) GetChannelPlan(ctx context.Context, site, id string) (*ChannelPlan, error) {
	return c.getChannelPlan(ctx, site, id)
}

func (c *Client) DeleteChannelPlan(ctx context.Context, site, id string) error {
	return c.deleteChannelPlan(ctx, site, id)
}

func (c *Client) CreateChannelPlan(ctx context.Context, site string, d *ChannelPlan) (*ChannelPlan, error) {
	return c.createChannelPlan(ctx, site, d)
}

func (c *Client) UpdateChannelPlan(ctx context.Context, site string, d *ChannelPlan) (*ChannelPlan, error) {
	return c.updateChannelPlan(ctx, site, d)
}

It would be a good starting point to have full coverage of generated structs with client code, which then could be customized as needed.

@joshuaspence
Copy link
Collaborator

So the original idea here was to make it explicit which methods were exposed rather than just exposing everything. If we want to expose everything then there's no need for a separate template, just change the visibility in the existing template.

@filipowm
Copy link
Contributor Author

filipowm commented Jan 3, 2025

So the original idea here was to make it explicit which methods were exposed rather than just exposing everything. If we want to expose everything then there's no need for a separate template, just change the visibility in the existing template.

Got it. I thought to expose everything, especially that this client is not only used by terraform-unifi-provider and others could benefit from that. However, there is a risk some functionalities may be broken. Then we can hope for reporting those and some contributions to fix them.

@joshuaspence
Copy link
Collaborator

joshuaspence commented Jan 7, 2025

I think there's a bigger question here about what this library supports. This library primarily exists for terraform-provider-unifi and whilst there is undoubtedly other usage in the wild, I have no real insights into how it is being used, what functionality is important, what version support is needed. As such, I haven't really worried too much about making breaking changes and/or testing since it gets tested as part of the Terraform provider.

If we want to make it easier to expose methods from go-unifi, it might be worthwhile setting up some testing infrastructure to ensure that we can actually maintain compatibility

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

2 participants