Skip to content

docs: Update Golang code snippets for the "Feature" section#12407

Merged
ivanagas merged 6 commits intoPostHog:masterfrom
vdekrijger:vassiedk-fix-doc-typos
Aug 11, 2025
Merged

docs: Update Golang code snippets for the "Feature" section#12407
ivanagas merged 6 commits intoPostHog:masterfrom
vdekrijger:vassiedk-fix-doc-typos

Conversation

@vdekrijger
Copy link
Contributor

@vdekrijger vdekrijger commented Aug 10, 2025

Changes

Please refer to this PR for the context of this doc update (to avoid repetition).

I've ran this project locally in order to observe how the documentation adjustments render. Screenshots of this can be found below:

Rendering of the feature-flag sample Go code:
Scherm­afbeelding 2025-08-10 om 20 14 22

Rendering of the sendFeatureFlags segment:
Scherm­afbeelding 2025-08-10 om 21 13 47

Rendering of the err variable assignment:
Scherm­afbeelding 2025-08-10 om 20 19 28

Rendering of the experiment sample Go code:
Scherm­afbeelding 2025-08-10 om 20 19 05

This closes PostHog/posthog-go#114

@vercel
Copy link

vercel bot commented Aug 10, 2025

Someone is attempting to deploy a commit to the PostHog Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This PR fixes critical syntax issues in Go code snippets across the PostHog documentation to ensure they compile and follow Go best practices. The changes address three main areas:

  1. Package Prefixing: Adds the required posthog. prefix to struct types like FeatureFlagPayload and FeatureFlagPayloadNoKey throughout the documentation, which is necessary for proper Go compilation when using the PostHog SDK.

  2. Error Handling: Introduces comprehensive error handling patterns with if err != nil blocks after all function calls that return errors, demonstrating proper Go practices and preventing potential runtime issues.

  3. Code Formatting: Improves overall code structure and formatting to align with Go conventions, including proper variable assignment patterns and trailing commas in struct initialization.

The changes span three documentation files: the experiments guide (adding-experiment-code.mdx), feature flags code snippets (feature-flags-code-go.mdx), and the main Go library documentation (go/index.mdx). These updates ensure that developers can copy-paste the code examples and have them work immediately in their Go applications, while also learning proper PostHog SDK usage patterns. The changes are directly tied to resolving GitHub issue #114 in the posthog-go repository, indicating this was driven by actual user feedback about non-functional documentation examples.

Confidence score: 5/5

  • This PR is extremely safe to merge with no risk of breaking functionality
  • Score reflects simple documentation fixes that improve code quality without affecting any runtime behavior
  • No files require special attention as these are purely documentation improvements

3 files reviewed, 1 comment

Edit Code Review Bot Settings | Greptile

isMyFlagEnabled, err := client.IsFeatureEnabled(posthog.FeatureFlagPayload{
Key: "flag-key",
DistinctId: "distinct_id_of_your_user",
SendFeatureFlagEvents: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The SendFeatureFlagEvents is set to true but the preceding text says this is for disabling the events. Should this be false?

Suggested change
SendFeatureFlagEvents: true,
SendFeatureFlagEvents: false,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Amazing that AI caught this 😃 ; Updated the documentation to have this set to false as well, based upon my observations that this was also the case for the PHP code example.

@vdekrijger
Copy link
Contributor Author

@greptile-apps

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Greptile Summary

This review covers only the changes made since the last review (commit bf00530), not the entire PR.

The most recent changes address the previous review feedback by implementing a more comprehensive fix to the Go feature flags documentation. The developer has corrected the boolean value issue identified earlier but has gone further to provide version-specific guidance and fix a critical API usage error.

The key changes include:

  1. Adding version-specific information distinguishing between pre-v1.6.1 and post-v1.6.1 behavior
  2. Fixing the Go SDK API usage by using a pointer to boolean (&sendFeatureFlags) instead of a direct boolean value for the SendFeatureFlagEvents field
  3. Clarifying that the feature is disabled by default in newer versions
  4. Creating a separate variable sendFeatureFlags := false to properly demonstrate the pointer usage

These changes ensure the documentation accurately reflects both the SDK's API requirements (expecting *bool rather than bool) and provides clear guidance for users working with different SDK versions. The fix addresses the original issue from the PostHog Go SDK repository while improving the overall clarity of the documentation.

Confidence score: 5/5

  • This PR is safe to merge with minimal risk as it only corrects documentation accuracy
  • Score reflects thorough documentation fixes that address API usage errors and version differences
  • No files require special attention beyond the single documentation file updated

1 file reviewed, no comments

Edit Code Review Bot Settings | Greptile

@vercel
Copy link

vercel bot commented Aug 11, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog ✅ Ready (Inspect) Visit Preview Aug 11, 2025 7:03am

Copy link
Contributor

@ivanagas ivanagas left a comment

Choose a reason for hiding this comment

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

nice, thank you!

@ivanagas ivanagas enabled auto-merge (squash) August 11, 2025 06:49
@ivanagas ivanagas merged commit 06fffbc into PostHog:master Aug 11, 2025
4 checks passed
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.

Go onboarding incorrect code example on us.posthog.com

2 participants