Skip to content

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

Merged
haacked merged 1 commit intoPostHog:masterfrom
vdekrijger:vdekrijger-fix-go-feature-flag-snippets
Aug 11, 2025
Merged

docs: Update Golang code snippets for the "Feature" section#36423
haacked merged 1 commit intoPostHog:masterfrom
vdekrijger:vdekrijger-fix-go-feature-flag-snippets

Conversation

@vdekrijger
Copy link
Contributor

@vdekrijger vdekrijger commented Aug 10, 2025

Problem

Whilst reading the documentation about feature flags and experiments, I noticed that some of the Go snippets were missing the posthog. import prefix and/or were ignoring error handling. In order to improve the potential first impressions / copyability of the code, I quickly updated them to help out future readers.

The indentation adjustments are solely for the sake of aligning with the other code samples, I've included screenshots below to show how it renders, but happy to leave the indentation as is if that is your preferred style 😃 !

I've also noticed it was listed as an issue in the Golang SDK, therefore, this update also closes PostHog/posthog-go#114.

I have also submitted PRs for fixes in the posthog.com repo, and the posthog-go repo so everything is aligned:

Changes

Rendering of the feature-flag sample Go code:
Scherm­afbeelding 2025-08-10 om 19 50 59

Rendering of the feature-flag sample Go code with local evaluation options enabled:
Scherm­afbeelding 2025-08-10 om 19 50 54

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

How did you test this code?

I ran the PostHog system locally in order to observe how the changes in documentation would render on the pages. Please refer to the screenshots above to see.

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

…o fix typo and act upon the potential error
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 improves the quality of Go code snippets in PostHog's documentation by fixing compilation issues and adding proper error handling. The changes affect two files that generate code snippets for feature flags and experiments.

In FeatureFlagSnippets.tsx, the Go snippet function (GolangSnippet) now includes the proper posthog. package prefix when initializing FeatureFlagPayload structs, which was previously missing and would cause compilation errors. The code also adds essential error handling with an if err != nil block, following Go best practices. Additionally, the indentation has been adjusted to align with other language examples in the documentation.

Similar improvements were made in ExperimentCodeSnippets.tsx to the GolangSnippet function, ensuring consistency across all Go code examples in PostHog's documentation. These changes address issue #114 in the PostHog Go SDK repository and significantly improve the developer experience by providing copy-paste ready code that actually compiles and follows Go conventions.

The modifications integrate well with the existing codebase structure, which already has established patterns for generating language-specific code snippets through TypeScript functions that return JSX elements containing CodeSnippet components.

Confidence score: 5/5

  • This PR is extremely safe to merge with virtually no risk of breaking existing functionality
  • Score reflects simple, well-targeted improvements to documentation code snippets with clear benefit and no side effects
  • No files require special attention as the changes are straightforward documentation improvements

Context used:

Context - Default templates for code should be clear and useful, providing examples of how to write the code effectively, rather than relying solely on documentation. (link)

2 files reviewed, no comments

Edit Code Review Bot Settings | Greptile

@gewenyu99
Copy link
Contributor

Not enough context for a review, but your border collie is beautiful. Compliments from a fellow border collie owner 🐕

Copy link
Contributor

@haacked haacked left a comment

Choose a reason for hiding this comment

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

Changes look good to me. Thanks!

@haacked haacked requested a review from orian August 11, 2025 19:07
@haacked
Copy link
Contributor

haacked commented Aug 11, 2025

@orian these looked good to me but I pinged you as our resident Go expert in case you had some thoughts for further improvements. I'll merge this when everything passes.

@haacked haacked enabled auto-merge (squash) August 11, 2025 19:08
@haacked haacked merged commit 41fe19e into PostHog:master Aug 11, 2025
143 of 158 checks passed
@vdekrijger
Copy link
Contributor Author

Thanks @gewenyu99 😊 ! They're such an amazing breed!

Thanks @haacked / @orian for the speedy reviews (also in the other PR), appreciate it! 🙌

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

3 participants