openfga / sdk-generator

OpenFGA Client SDK Generator
Apache License 2.0
14 stars 30 forks source link

feat(go-sdk): Allow StoreId to be overridden per-request #364

Closed jimmyjames closed 1 month ago

jimmyjames commented 1 month ago

Enables overriding the store ID using client.go for all APIs except for ListStores and CreateStore.

Description

For endpoints that use the store ID, a StoreId was added to its respective request options. If set, it will be used when making the request. If not set, the store ID configured for the client will be used instead.

client, err := NewSdkClient(&ClientConfiguration{
         ApiUrl:  os.GetEnv("FGA_API_URL"),     
         StoreId: os.GetEnv("FGA_STORE_ID"),
})

if err != nil {
        // handle error
}

// Uses StoreId from ClientConfiguration
got, err := client.GetStore(context.Background()).Execute()
if err != nil {
        // ....
}
fmt.Printf("Got store %v", got.Name)

// store can be overridden
storeOverrideOptions := ClientGetStoreOptions{
    StoreId: "01RXYB9SWCFGFCX1QZA9DN8T4Y",
}

got, err = client.GetStore(context.Background()).Options(storeOverrideOptions).Execute()
if err != nil {
    // ....
}

fmt.Printf("Got store %v", got.Name)

References

Completes the go-sdk work captured in #118

Review Checklist

jimmyjames commented 1 month ago

Will update this once again after https://github.com/openfga/sdk-generator/pull/366 is merged, then update the go-sdk PR from generation.