exoscale / egoscale

exoscale golang bindings
https://pkg.go.dev/github.com/exoscale/egoscale/v3
Apache License 2.0
31 stars 15 forks source link

v3: ForEachZone helper and logging #594

Closed kobajagi closed 11 months ago

kobajagi commented 11 months ago

Example usage of ForEachZone and logging with builtin Logger implementation (StandardLogger):

func main() {
    client, err := exoscale.DefaultClient(
        exoscale.ClientOptWithCredentialsFromEnv(),
        exoscale.ClientOptWithLogger(exoscale.NewStandardLogger(os.Stdout, true)),
    )
    if err != nil {
        panic(err)
    }

    client.ForEachZone(func(c *exoscale.Client, zone oapi.ZoneName) {
        l, err := c.Compute().LoadBalancers().Get(context.Background(), <id>)
        if err != nil {
            fmt.Println(err)
        } else {
            fmt.Println(l)
        }
    })
}
shortcut-integration[bot] commented 11 months ago

This pull request has been linked to Shortcut Story #71887: Additional client middlewares.

sauterp commented 11 months ago

Could it be useful to have an optional argument for ForEachZone that allows users to specify a subset of the zones? It could be a list of zones. Or maybe we could use the option pattern, so that you can for example use v3.SwissZones. Just an idea.

kobajagi commented 11 months ago

Could it be useful to have an optional argument for ForEachZone that allows users to specify a subset of the zones?

Idk if that is the usecase that justifies extra code. Helpers should solve common problems, zones subset iteration doesn't sound common (i cannot think of any usage internally). I'd left it for consumers to implemen.