-
Notifications
You must be signed in to change notification settings - Fork 23
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
Make API values optional #27
Comments
I expected something like this to happen when I added params := &sceneitems.SetSceneItemPropertiesParams{
SceneName: "main",
Item: &typedefs.Item{Name: "bg"},
Visible: &[]bool{false}[0],
Locked: &[]bool{false}[0],
} I suppose there's no getting around this tradeoff if it makes the library more robust and consistent though, is there? |
Hmm... so after making the change in that PR, I realized it also changes response bodies returning boolean values. Do you think this is okay? I could have only request bodies expect pointers to bools, but that inconsistency would bother me. |
It would probably feel more natural to have values in the response body, as their value isn't optional in that case - unless you plan to support multiple versions of the websockets API and want |
I'm afraid I agree. It's not exactly nice, but it's the correct solution to this tri-state (true, false, unknown). There are two alternatives I can think of to make the code a bit more readable:
func BoolPtr(b bool) *bool {
boolVar := b
return &boolVar
}
scenes.NewSetCurrentSceneRequest().
WithSceneName(name).
WithFoo(bar).
With... A third option would involve reflection, but I think we'd want to avoid that 😆 |
Sorry for the wait!
This makes sense. Thank you for the feedback 🙏 I added a conditional to set
I do really like this. It's similar to the funcops I have for the constructor but chained. I'd have to explore this pattern when I take a stab at the v5 protocol. Would be cool to offer both APIs. |
Released in v0.8.0! |
seems like i undid this moving to v5 see this discussion #27
seems like i undid this moving to v5 see this discussion #27
* simplify generation code for Object/Array<Object> fields * address all the unhandled Object/Array<Object> types * handle special case for InputVolumeMeters' inputs * generate builders for request param structs * use pointers to primitives everywhere (see #27 #60) * use ints for Number fields ending in Id or Index * fix types in test generation * update examples * use any instead of interface{} * set the raw json message on each response * nit: it's _technically_ an error * make generate * internal: move the mappers to their own separate file --------- Co-authored-by: Andrey Kaipov <andreykaipov@users.noreply.github.com>
It would be nice if values like
SetSceneItemPropertiesParams
'sLocked
orRotation
were pointers to their values, making setting them optional. Currently forgetting to set that member value will essentially reset the Locked status or Rotation.The biggest risk I see here is that newer versions of the OBS Websockets API and this library will introduce new member values. Bumping the
goobs
dependency (e.g. in obs-cli) is a bit risky then, as any unhandled member values could potentially cause unexpected behavior.See: muesli/obs-cli#34
The text was updated successfully, but these errors were encountered: