Skip to content

Callback nil check#28

Merged
linglingye001 merged 3 commits intorelease/v1from
linglingye/onRefreshSuccess
Jun 9, 2025
Merged

Callback nil check#28
linglingye001 merged 3 commits intorelease/v1from
linglingye/onRefreshSuccess

Conversation

@linglingye001
Copy link
Member

No description provided.

// - callback: A function with no parameters that will be called after a successful refresh
func (azappcfg *AzureAppConfiguration) OnRefreshSuccess(callback func()) {
if callback == nil {
log.Println("callback cannot be nil")
Copy link
Member

Choose a reason for hiding this comment

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

No need to log that

if callback != nil {
callback()
}
callback()
Copy link
Member

@RichardChen820 RichardChen820 Jun 6, 2025

Choose a reason for hiding this comment

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

This check is still necessary, don't remove it, check nil before using always right

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you saying that the callback can be changed during runtime?

Copy link
Member

@RichardChen820 RichardChen820 Jun 6, 2025

Choose a reason for hiding this comment

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

At least in .net, using reflection can mutate any object at runtime (via reflection), Go also support reflection, not sure it's also feasible for Go or not, but nil check before use should always be right.

@linglingye001 linglingye001 merged commit 81cd8f3 into release/v1 Jun 9, 2025
13 checks passed
@linglingye001 linglingye001 deleted the linglingye/onRefreshSuccess branch June 9, 2025 06:51
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.

2 participants