docs: Update Golang code snippets for the "Feature" section#12407
docs: Update Golang code snippets for the "Feature" section#12407ivanagas merged 6 commits intoPostHog:masterfrom
Conversation
|
Someone is attempting to deploy a commit to the PostHog Team on Vercel. A member of the Team first needs to authorize it. |
There was a problem hiding this comment.
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:
-
Package Prefixing: Adds the required
posthog.prefix to struct types likeFeatureFlagPayloadandFeatureFlagPayloadNoKeythroughout the documentation, which is necessary for proper Go compilation when using the PostHog SDK. -
Error Handling: Introduces comprehensive error handling patterns with
if err != nilblocks after all function calls that return errors, demonstrating proper Go practices and preventing potential runtime issues. -
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
| isMyFlagEnabled, err := client.IsFeatureEnabled(posthog.FeatureFlagPayload{ | ||
| Key: "flag-key", | ||
| DistinctId: "distinct_id_of_your_user", | ||
| SendFeatureFlagEvents: true, |
There was a problem hiding this comment.
logic: The SendFeatureFlagEvents is set to true but the preceding text says this is for disabling the events. Should this be false?
| SendFeatureFlagEvents: true, | |
| SendFeatureFlagEvents: false, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- Adding version-specific information distinguishing between pre-v1.6.1 and post-v1.6.1 behavior
- Fixing the Go SDK API usage by using a pointer to boolean (
&sendFeatureFlags) instead of a direct boolean value for theSendFeatureFlagEventsfield - Clarifying that the feature is disabled by default in newer versions
- Creating a separate variable
sendFeatureFlags := falseto 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
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
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:

Rendering of the sendFeatureFlags segment:

Rendering of the err variable assignment:

Rendering of the experiment sample Go code:

This closes PostHog/posthog-go#114